Run - Time polymorphism with Overriden method in JAVA
Hello Friends,
I am New to this forum as well as New to the Programming world of JAVA, I am little bit confused about how run-time polymorphism takes place in the Overridden method.It would be much more helpful for me, If anyone suggest this with an self explanatory code.Please help.
Thanks for all those who replies.
Re: Run - Time polymorphism with Overriden method in JAVA
Hi NAYASA,
I will like to help you,Check the solution below, this will help you to understand the Run Time polymorphism in Override method.
Quote:
class A
{
int num1,num2;
void calc(int a,int b)
{
num1=a;
num2=b;
}
void show()
{
System.out.println("Calling Method from A");
}
}
class B
{
super(a,b);
void show()
{
System.out.println("Calling Method from B");
return num1*num2;
}
}
class C
{
super(a,b)
void show()
{
System.out.println("Calling Method from B");
return num1*num2/2;
}
}
class override{
public static void main(String args[])
A a = new A();
B b = new B();
C c = new C();
A ref = new A();
ref =b;
ref.show();
}