Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
Originally posted by amatya:
Which of the following method definitions will prevent overriding of that method? (Select 2 right answers)
public final void method m1() //1
public static void method m1() //2
public static final void method m1() //3
public abstract void method m1() //4
private void method m1() //5
Right answer: 1 and 5.
Why not 1 and 3?
Another comment: the question itself looks wrong. you cannot declare a "public void method m1()" can you? Shouldn't it be simply "public void m1()"???
public final void methodM1() //1
public static void methodM1() //2
public static final void methodM1() //3
public abstract void methodM1() //4
private void methodM1() //5
Rob
SCJP 1.4
Originally posted by Rob Ross:
Now these at least make syntactic sense. As for the answers to the original question:
1 is correct, because you cannot override a final method
2 is correct, because you cannot override a static method. (Static methods can be hidden, but not overridden.)
3 is correct, because the method is both final and static and therefore cannot be overriden
5 is correct because private methods in a superclass are not inherited by the subclass; since they're not inherited, they cannot be overriden.
So the only declaration that can be overriden is 4. The answer to the question "Which of the following method definitions will prevent overriding of that method? " is 1,2,3 and 5.
Rob
[ January 17, 2002: Message edited by: Rob Ross ]
Regards,
Jim
SCJP, SCJD, SCWCD, SCEA Part I
Originally posted by Shivaji Marathe:
Jim :
Repeat after me![]()
"Static methods can not be overridden. They only hide the static methods in the superclass."
You certainly can create a static method in a subclass, with the same name, signature and return type as the parent class static method. BUT you can NOT then call the parent's static method as super.staticMethod() from your subclass.
Any non static, non private methods in the super class can always be called in the subclass as
super.nonStaticMethod() etc. That is the difference between overriding and hiding.
Hope this helps.
Now , EVERYBODY repeat after me![]()
"Static methods can not be overridden. They only hide the static methods in the superclass."
Regards,
Jim
SCJP, SCJD, SCWCD, SCEA Part I
Originally posted by Rob Ross:
1 is correct, because you cannot override a final method
2 is correct, because you cannot override a static method. (Static methods can be hidden, but not overridden.)
3 is correct, because the method is both final and static and therefore cannot be overriden
5 is correct because private methods in a superclass are not inherited by the subclass; since they're not inherited, they cannot be overriden.
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Although I don't want to offend anyone, I really don't trust alot of what folks write in forums and on web pages - I've run into alot of mistakes - especially in the mock tests.
I've been studying for the exam for over 5 months - I could pass it easily right now with no problem, but I'm trying to get a perfect score.
Regards,
Jim
SCJP, SCJD, SCWCD, SCEA Part I
Originally posted by Valentin Crettaz:
To Jim Bedenbaugh,
I'm really sorry I wanted to reply to your message but I edited it instead of quoting it (the buttons are just next to each other...)
I'm REALLY REALLY sorry, could you please post your message again...
I dunno what to say... except SORRY AGAIN...
Regards,
Jim
SCJP, SCJD, SCWCD, SCEA Part I
Originally posted by Jim Bedenbaugh:
I have learned that a great number of things I have read in forums and on web pages are incorrect.
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Originally posted by Shivaji Marathe:
Proof of the pudding is in the eating:
Try these two programs.
and
Hope this helps
Wagner Danda<br />Sun Certified Programmer for Java 2 Platform
Originally posted by Wagner Danda:
and
Hope this helps<hr></blockquote>
I can�t compile this code... it says:
*** Error: A "super" expression may only appear in the body of a class that has a super class and it must be enclosed in the body of an instance method or constructor or in the initializer of an instance variable.
What�s happening?[/QB]
Wagner Danda<br />Sun Certified Programmer for Java 2 Platform
Originally posted by Jim Bedenbaugh:
No problem. Basically, all I said was that although I understand static methods are hidden, sematically and lexigraphically they are no different than overriden
I have learned that a great number of things I have read in forums and on web pages are incorrect.
If a class declares a static method, then the declaration of that method is said to hide any and all methods with the same signature in the superclasses and superinterfaces of the class that would otherwise be accessible to code in the class.
Rob
SCJP 1.4
Rob
SCJP 1.4
Originally posted by Rob Ross:
This is like saying "I know the earth is round, but visually it is no different than being flat, therefore it is the same as being flat."
Your argument isn't logical.
Rob
Regards,
Jim
SCJP, SCJD, SCWCD, SCEA Part I