Object vocabulary

In the table below, each cell contains a description of how the thing in the first column of the row relates to the thing at the head of the column.

Class Object Instance Instance variable Constructor Instance method
Class Classes define the structure and behavior of objects that are instances of that class. Classes can have many instances. Classes define the instance variables that each instance of the class will have. Classes define the constructor or constructors used to create and initialize instances of a the class. Classes define the instance (non-static) methods that can be called on instances of the class.
Object Each object is an instances of a class. “Object” is another word for “instance”. Each object has its own value for each instance variable. An object is created and initialized by invoking a constructor. Objects have methods that can be invoked on them via the dot operator.
Instance An instance is a particular object with a structure defined by its class. “Instance” is another word for “object”. Each instances contains its own copy of the class’s instance variables. An instance created and initialized by calling a constructor. Instances supports the methods defined in the class.
Instance variable Instance varables are declared (i.e. given their types and names) at the top level of a class to define a piece of data associated with each instance of the class. Instance variables stores the data associated with an object and can be accessed with the dot operator applied to an object value. Each instance variable represents part of the state of an instance. Instance variables are usually initialized in the code of a constructor. Instance variables can be accessed by code in instance methods.
Constructor Constructors are declared at the top level of a class to specify how to create instances of that class. A constructor always produces a new object when invoked. A constructor creates and initializes an instance of the class it is part of. Constructors have the job of initializing instance variables so objects are ready to use after the are constructed. A constructor is a bit like a method in that it contains code and has access to an object’s instance variables but rather than a return type and a name just has a name which matches the class name.
Instance method Instance methods are declared at the top level of a class to define the behaviors that can be invoked on instances of the class. Instance methods provide the behaviors of objects and are invoked on objects via the dot operator. Instance methods can only be invoked if you have an instance to invoke them on. Instance methods can access instance variables on the object they were invoked on just by their plain name, e.g. x, or using the notation this.x. Instance methods cannot run until the object has been created but can be called from within the code of the constructor.