Classes and objects
Before we go further, it is important that you understand these two key concepts. A class is a template or a blueprint that specifies the form of an object. It contains both data and code that operates on that data. An object is an instance of a class. Classes are defined using the class
keyword and a type that is a class is a reference type. The default value for a variable of a reference type is null
. You can assign it as a reference to an instance of the type. Instances—that is, objects—are created using the new
operator.
Information box
The terms class and object are often used interchangeably in different technical documentations. They are not the same and it is improper to use them as so. The class is the blueprint that specifies the memory layout of objects and defines functionalities that operate with that memory. Objects are the actual entities created and operated according to the blueprint.
Take a look at the following code snippet...