This section will expand on the concepts of object construction

  • Declare a variable named "Rec" of type "Rectangle"
  • Java keyword "new" constructs object
  • A valid type (i.e. the "Rectangle" class we worked on)

We will use the same Declare Then Use pattern as is in the "Using Variables" section.

The "=" operator is the assignment operator meaning the right side is assigned to the variable "rec"
1
Rectangle rec; rec =
2
new
3
Rectangle();
  • Declare two variables of type "Rectangle"
  • Construct objects (and assign to variables)
1
//Declare Vars Rectangle rec1, rec2;
2
//Construct Objects rec1 = new Rectangle(); rec2 = new Rectangle();
  • Declare the variables of desired types and names
  • Construct objects (and assign to the appropriate variable)
1
//Declare Vars Rectangle rec; Shape shape; Person p;
2
//Construct Objects rec = new Rectangle(); shape = new Shape(); p = new Person();