What is the result? A 4243 B 4342 C Compilation fails due only to an error on line #1 D Compilation fails due only to an error on line #2 E Compilation fails due to errors on both lines #1 and #2 F An exception is thrown at runtime
The answer provided is C. But i don't see any error on line #1. Can anyone clarify this?
[HENRY: Added code tags] [ October 28, 2006: Message edited by: Henry Wong ]
The language specification says, that static methods aren't overridden but hidden. If you do call it also overriding, then the sentence would be not correct. Because you cannot call a static method with super.
Anyway, I think it's just easier to memorize if you say: "You can't use super or this in a static context."
This is false. You CAN call static methods using super. Actually that was all about within my question.
Yes, you can call a static method using super. But in this case, the "this" (and "super") is not available -- since you are in a static context.
BTW, even if it is in context, it is not a good idea. You should access static methods via the class name (like AlternateFuel.getRating2()). It makes it easier to remember which methods are static and which are not.
Henry [ October 28, 2006: Message edited by: Henry Wong ]