Summary
In this chapter, we started our discussion by differentiating objects and classes. Classes are similar to a plan of a house, whereas an object is the (built) house itself. We create an object using the new
keyword and manipulate the object using its reference. Differentiating the reference from the object is very important going forward. A useful analogy is that the reference is like a remote control and the object is the TV.
Constructors are special methods that are used when constructing an object. The constructor is a method that has the same name as the class but with no return type. There is always a constructor present – if you don’t provide one, the compiler intervenes and inserts the default constructor. The constructor is typically used to initialize the instance variables.
Every object gets a copy of the instance members (variables and methods). Class members are marked as static
, and are shared by all instances. When accessing an instance member...