Hello everybody,
I am sorry the code is not aligned properly. I have these questions regarding this code.
The output of the program is
i 10 num 5
num 5
num 6
I am methodA of Sub
When I do Super sup = new Sub();
1. Why does it associate variables(num) with the reference type ie Super.When I say sup.num it prints out the num in parent class.
2. It applies the same rule with methods also, it doesn't allow me to call any mehtods which exists only in child class.See the commented call to methodB()
3. If that's so, I mean you have to have methods existing in the parent class, why doesn't it apply the same rule to constructors? I am allowed to do Super sup = new Sub() eventhough I don't have a constructor with no arguments in the
parent.
I hope I am clear in my questions
Thanks
Sudha
[I added UBB CODE tags to your source code to make it more readable. Please try to use
them in the future.
Learn more about UBB codes here - Ajith ]
[This message has been edited by Ajith Kallambella (edited November 22, 2000).]