It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes super keyword doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "super keyword doubt" Watch "super keyword doubt" New topic

super keyword doubt

Aditya Kumar
Ranch Hand

Joined: Oct 31, 2006
Posts: 102

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?


aditya kumar
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 446

[EDIT]removed due to misconception and providing wrong explanation[/EDIT]
sorry for inconvenience

SCJP 6 [86%], OCPWCD [84%], OCEJPAD [83%]
If you find any post useful, click the "plus one" sign on the right
Imad Aydarooos
Ranch Hand

Joined: Nov 02, 2010
Posts: 87
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:

love demgracy, knowledge demogracy, open source and Java - OCPJP 76%
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Imad Aydarooos is correct, You can't use either super or this keywords within a static contexts, because, they belonging to instances of objects.

|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
I agree. Here's the link:
subject: super keyword doubt
It's not a secret anymore!