• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

super keyword doubt

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If I wasn't nervous, I'd put the subject line as "super doubt". Nevertheless..

Consider these two classes:



And the second class:



This is from the learnkey exam. It says that the compilation will fail because of #1 and that "Only instance methods can be overridden, and calls to super only apply to overridden methods". I understand (and please correct me if I am wrong) that getRating2 is a static method so overriding it is out of question, but here is my doubt: what is the point of using super to access getRating()? Is it just to confuse?

thanks,

aditya kumar
 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[EDIT]removed due to misconception and providing wrong explanation[/EDIT]
sorry for inconvenience
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear Aditya Kumar , I think the explanation as you wrote it from LearnKing is not confusing but its rather wrong. the cause of compilation error is because super is not available in the main() method, we all know main() is static and super and this are not available there.
look to your code after making vew ammedments:
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Imad Aydarooos is correct, You can't use either super or this keywords within a static contexts, because, they belonging to instances of objects.
 
reply
    Bookmark Topic Watch Topic
  • New Topic