• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

q from jiris.com on overriding

 
JayaSiji Gopal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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?
 
Animesh Shrivastava
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Adeeb Abdul Karim
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it's a simple as that: class Super does not have a method called "method".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic