Social Icons

twitterfacebookgoogle pluslinkedinemail

Thursday 15 August 2013

what is the upcasting

upcasting means that the hive reference of child class to parent class.

In the upcasting ,there are multiple child class for one parent class so the parent class can access the property of child class.

class A
{
void getA()
{
System.out.println("this is class getA metho for A class");
}
}

 
class B extends A
{
void getB()
{
System.out.println("this is class getB metho for B class");
}
}
class C extends A
{
void getC()
{
System.out.println("this is class getC metho for C class");
}
}
class D extends A
{
void getD()
{
System.out.println("this is class getD metho for D class");
}
}
class demo
{
public static void main(String args[])
{
A a1 = new A();
B b1 = new B();
C c1 = new C();
D d1 = new D();

a1 = b1;
a1.getB();
a1 = c1;
a1.getC();
a1 = d1;
a1.getD();
}
}
this is also called as a dynamic method dispatch.
there are give the reference of child class to parent class and parent class access the property of child class.

No comments :

Post a Comment

 

Free Advertisement

Free Advertisement

Free Advertisement

Free Advertisement