Ask Question
6 March, 05:27

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.

+2
Answers (1)
  1. 6 March, 05:55
    0
    public ApartmentBuilding (Address addr, int sqFoo, int totUn) {

    super (addr, sqFoo);

    this. totalUnits = totUn;

    }

    Explanation:

    To pass up parameters from a subclass constructor to a superclass constructor you just need to define a parameter name in the subclass constructor (in this case addr and sqFoo, but it can be anything you like) and then use the keyword super.

    The keyword super acts exactly the same as the constructor of the superclass, however that may be defined.

    And for the rest of the parameters (E. G. the ones of the sub class) you just treat them as a regular constructor.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Assume the existence of a Building class with a constructor that accepts two parameters: a reference to an Address object representing the ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers