Forums Register Login

q from jiris.com on overriding

+Pie Number of slices to send: Send


I answered c and d, but the correct answer is c and e.
In line 1, the variable s at compile time is of reference type Super and at runtime is of type Test013. All method invocations are resolved at runtime. Hence, I feel the cast is not necessary.
Am i right? any mistakes?
+Pie Number of slices to send: Send
Hello,
As u only said that during compile time the variable s is of reference type Super. So, while compilation it checks whether the method method() is present or not for the class Super.
And therefore it gives a compilation error.
So, i guess the correct answers are C and E
+Pie Number of slices to send: Send
Test013 object is created and a variable of type Super is holding it. This happens at runtime.

At compiler time the method is not visible for a variable of type Super, because it is not defined in it. So if we want to use the method, we have to cast it to a type where the method is defined, then only the compiler will realise that it is having such a method.

So E is correct.
+Pie Number of slices to send: Send
Yes, it's a simple as that: class Super does not have a method called "method".
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 582 times.
Similar Threads
Valiveru's Mock Exam: Question #7
q on overloading and overriding
Clarification needed
a simple brainer on inner classes
Casting????
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:25:46.