A small example code is given below...
class A {
A() {
System.out.println("Constructor of Class A");
}
void show() {
System.out.println("I m in Class A");
}
}
class B extends A {
B() {
System.out.println("Constructor of Class B");
}
void show() {
System.out.println("I m in Class B");
}
}
public class DynamicMethodDispatch {
public static void main(String a[]) {
A aobj;
aobj = new A();
aobj.show();
aobj = new B();
aobj.show();
}
}
Output:
Constructor of Class A
I m in Class A
Constructor of Class A
Constructor of Class B
I m in Class B
No comments:
Post a Comment