Consider a Java Class → Employee
A subclass would be → Manager → Special types of employees with extra features
Manager is a SUBCLASS of Employee
For Example, when we extend a parent class written by someone else (or extending a library class).
So , use parent class’s constructor using super
keyword.
<aside>
💡 Can use a subclass in place of a superclass.
Employee e = new Manager(...)
</aside>
But the following will not work.
Manger m = new Employee(...)
(Because all functionalities of Manger is not available to Employee)You can now write something like:
<aside>
💡 Employee[] e = new Manager(...)[100]
</aside>