As you know, a class provides the blueprint for objects. Therefore, to create an object, you must have a class of the appropriate type. Declaring a variable to refer to an object is not a necessary part of object creation. However, a variable declaration often appears on the same line as the code to create an object so we discuss declaring a variable to refer to an object here. The new operator is followed by a call to a constructor.
Constructors initialize the new object.
This notifies the compiler that you will use name to refer to data whose type is type . In addition to the primitive types, such as int and boolean , provided directly by the Java platform, classes and interfaces are also types. So to declare a variable to refer to an object, you can use the name of a class or an interface, as the variable's type. The sample program uses both the Point and the Rectangle class names as types to declare variables. Declare a variable, but don't create an object.