From: suma latha Pinninti
Q?: how to access child class method
through parent object
Ans:It's not possible to access child class method through parent object.
By using runtime polymorphism ,Parentclass object points to its child class object.
by using parent class object we can access only parent class methods ,but not child class methods.
if we call ,it gives compilation Error.
From: srikanth madupathi
if u want call child class method with parent reference u can
cal(parentclass pc=new childclas())
,but with parent object u cant call.
From: ch karthikv <chkvee...@gmail.com>
hi,
Child class methods calls with parent class object is not possible
as of knowledge
for example
class Parent{
public void add(){
System.out.println("we are in parent");
}
}
public class Child extends Parent{
public void sub(){
System.out.println("we are in child");
}
public static void main(String ar[]){
Parent p=new Parent();
p.add();
p.sub(); // it is not possible bcz a parent class obj cn't access
the child class members
//a child class obj can access child
& parent class members
//
}
}
}