One of the central concepts of object-oriented programming is the possibility to inherit functionality defined at a higher level in the system. This can be done by having a class hierarchy where a method in a subclass overrides a method in the super class (higher level).
The method in the subclass can still use the functionality in the same method in the super class by using the super function as in this example:
public void sellCar()
{
;
super();
}
This method implies that the class that the method belongs to, extends another class where the functionality in the method sellCar is already written or that the sellCar method is defined at a higher level in the class hierarchy in which this class belong.
In our example, we have a super class called Car that extends Object, and then we have we have Car_Economy, Car_Compact, Car_MidSize and Car_Luxury who all extend the class Car. Also, they override the toString method for all of these classes as shown in the next example done for the Car_Economy class:
public str toString()
{
str ret;
ret = "Economy";
return ret;
}
To make sure that all of the subclasses have the updated information about the super class it is a good idea to compile forward when modifying the class hierarchy.
This is done by right-clicking on the super class and selecting Add-Ins and Compile Forward. To see which methods that your class can use from parent classes, simply right-click on the class in the AOT and select Override Method.
No comments:
Post a Comment
Thank you for your thoughts. Your comment will appear in my blog shortly after review.
Have a great day!