A class is a blueprint that describes what its objects have and can do. An object is one thing built from that blueprint. The data an object holds lives in named fields (also called instance variables). For example, a Dog has a name and an age.
Dog
name
age
class Dog { String name; // a field int age; // a field }
This class says every Dog object will have a name and an age. It is a blueprint — no dog exists yet until we build one.
▶ Try it: the Dog class is defined for you. Run this to build a dog and fill in its fields, then change the values and re-run.
A class is a ___, and an object is a ___.
In class Dog { String name; int age; }, what are name and age?
class Dog { String name; int age; }
Match each term to what it means.
True or false?
Type exactly what this program prints.
class Cat { String name; } public class Main { public static void main(String[] args) { Cat c = new Cat(); c.name = "Tom"; System.out.println(c.name); } }