that since the method of parent is not visible in child the child method should not override. infact it should come as a new method in child not a overridden one .
Always Belive On Logic!!
SCJP2. Please Indent your code using UBB Code
secondly consider what will happen if i move this main method to parent class and import the package c containing the child class there will the polymorphism work then !!
Originally posted by Valentin Crettaz:
Mateen,
Concerning your moving the main into the Parent class:
you can move the main method in the Parent class but then you have to :
- import the Child class inside the Parent class
- declare your method "a" to be at least protected so that overriding works
When you run the Parent class the method "a" of the Child class gets called as expected...
HIH
Originally posted by Valentin Crettaz:
If you put main in the Parent class you still have to import c.Child
Then when you try to compile the compiler still complains about method a (in class child) being not correctly overridden which makes sense since Child is a subclass of Parent. method a in Parent is still visible in Child but not accessible !!!
The cast you are trying to do in Parent won't help since the runtime type of p won't change because you are casting it...
HIH
SCJP2. Please Indent your code using UBB Code
Consider Paul's rocket mass heater. |