September 2017
Beginner
402 pages
9h 52m
English
Inheriting in OOP means creating a new class, which extends another already existing class. The simplest form of inheritance is a child-parent pair of two classes.
In the previous sections, we created the House class. Let us use it as the parent class for another concept. We will create a ModernHouse class, which is a House with a solar roof panel. A bare House, which we created earlier in this chapter, contains four attributes—number of rooms, area, height, and address. The address attribute was an Address object in our previous examples but, in this section, we will keep it simple and assume that the address is a string:
class House { has $.rooms; has $.area; has $.height; has $.address;}
For a ModernHouse, another ...
Read now
Unlock full access