Overriding and Hiding Methods
When extending a class, it is possible to redefine some of the methods that are part of it. Overriding means to rewrite something's functionality. This is done by making a new declaration of the method with the same name and properties of the method from the original class. This is demonstrated in the following example. Note that we're continuing, for the sake of clarity, with Computer
and Tablet
, but they have been cleaned up so as not to make the example programs too long.
class Computer { Â Â Â Â public void whatIsIt() { Â Â Â Â Â Â Â Â System.out.println( "it is a PC"); Â Â Â Â } } class Tablet extends Computer { Â Â Â Â public void whatIsIt() { Â Â Â Â Â Â Â Â System.out.println( "it is a tablet"); Â Â Â Â } } class Example06 { Â Â Â Â public static void main(String[] args...