Posted By:
Mandar_Pohnerkar
Posted On:
Wednesday, April 24, 2002 05:10 AM
HI, class Parent{ public void show(){ System.out.println("in parent"); } } public class Child extends Parent{ public void show(){ System.out.println("in child"); } public static void main(String args[]){ Parent p; Child c=new Child(); } } Now,with the object of child class i want to access parent class method.I tried casting like c=(Parent)p; This way it com
More>>
HI,
class Parent{
public void show(){
System.out.println("in parent");
}
}
public class Child extends Parent{
public void show(){
System.out.println("in child");
}
public static void main(String args[]){
Parent p;
Child c=new Child();
}
}
Now,with the object of child class i want to access
parent class method.I tried casting like
c=(Parent)p;
This way it compiles but gives error at runtime.
and i dont want to use 'super' keyword.
So, is there any way to access parent class method
with the object of child class.?
This is possible in c++.
Why java doesn't support this ?
Thanking u.
Mandar P
<<Less