4
Answers

inheritence concept

in inheritence concept overridden concept is there  ,there i faced a problem i.e child class object is assigned to  the parent class reference .so we r accessing the methods with same signature in parent class and child class those only we r accessing. but we r unable acess the other memberes of child class. actually  my doubt is in memory point of view we r considered the what we r access the child class memberes by using parent class reference those r also same memory location why can't we r access the other methods of child class
for example


class A   //parent class
{
public void add()  //method
{
statments;
}

class B:A  //inheriting
{
public void add()   //assume overridden method we r access only these method only from parent class reference
{
statements;
}
public void sub()  //unable to access the method through parent class reference why?add and sub methods r stored in same memory location but we r access only add method why not sub method
{
statements;
}
}

   please help me the answer for my question.






Answers (4)