
class superclass
{
p.bark()
}
class subclass extends superclass
{
p.bark
}
{p.s.v.m()
superclass refvar = new subclass();
p.bark();
}
Now my questions 1.Why is necessary for parent to have a method in this case whether child have it or not? i am told that at compile time as reference variable is of superclass so compiler checks for this method in superclass at compile time, correct me if i am wrong anywhere.... 2.when compiler reads p.bark() where does it go next (i know child method overrides but i want to know that first it goes to superclass method or subclass and WHY?) 3.why subclass needs to have a access modifier of wider scope?
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.