• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

super() question - from sierra/bates practice exam

 
Rachel Glenn
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GIVEN:


WHAT IS THE RESULT?

The answer is that COMPILATION FAILS AT LINE #1 because "only instance methods can be overriden, and calls to super only apply to overriden methods".



I don't get this. Can someone explain? It seems valid to me.... I would have guesses that this compiled!
 
Deepak Kumar Jha
Greenhorn
Posts: 18
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first of all you cannot use super keyword in static context. that is at line 9 super.getRating2() is not valid.

after removing super the program is compiling and running fine. output: 42 43 .
 
Rachel Glenn
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ugh, I am now embarassed I even asked this question. Of course you can't use super from within a static method! That is the same as trying to use this. thank you!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic