Runtime Polymorphism
class A extends Object{
public void m(){
System.out.println("m in class A");
}
}
class B extends A{
public void m(){
System.out.println("m in class B");
}
}
public class Runtime{
public static void main(
String[] args){
A a = new A();
B b = new B();
a = b;
b.m(); //method in subclass is called
}
}
0 Comments:
Post a Comment
<< Home