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...