Assume the existence of a Building class with a constructor that accepts two parameters: a reference to an Address object representing the building's address, and an integer for the square footage of the building. Assume a subclass ApartmentBuilding has been defined with a single integer instance variable, totalUnits. Write a constructor for ApartmentBuilding that accepts three parameters: an Address and an integer to be passed up to the Building constructor, and an integer used to initialize the totalUnits instance variable.

public ApartmentBuilding(Address address, int squareFootage, int totalUnits) {
super(address, squareFootage);
this.totalUnits = totalUnits;
}

Respuesta :

Answer:

public ApartmentBuilding(Address address, int squareFootage, int totalUnits) {

super(address, squareFootage);

this.totalUnits = totalUnits;

}

Answer:

It seems you already answered your own question, but let me explain the steps so that it will all be clear for you.

Explanation:

A constructor has no return type, has the name as the class name, and can take parameters.

According to the requirements, the ApartmentBuilding constructor takes three parameters: address, squareFootage, and totalUnits. Inside the body of the constructor, we need to initialize these variables.

Be aware that the address and squareFootage is initialized by using super keyword. That means, the constructor of the parent class - Building  is invoked.

ACCESS MORE
EDU ACCESS