+ 2
They are very important for scenarios where polymorphism is used. Consider the following classes: class A { public void print () { System.out.println("A"); } } class B extends A { public void print() { // we're overriding the behaviour from A System.out.println("B"); } } Now consider creating two objects: A objA= new A(); A objB= new B(); Since the behaviour is different for the concrete objects, although stored in the same type of A, calling print on both objects will print different results on the console output: objA.print(); // prints A objB.print(); // prints B
28th Nov 2016, 5:47 AM
Kerem AdıgĂŒzel
Kerem AdıgĂŒzel - avatar