Declaring an Object

Like other variable declarations, object declarations can also appear alone, like this:

Rectangle rect;
Declarations notify the compiler that you will use name to refer to a variable whose type is type. Declarations do not create new objects. Rectangle rect does not create a new Rectangle object, just a variable named rect to hold a Rectangle object.

To create a Rectangle object, or any other object, use the new operator.

Scroll to Top