aspose file tools*
The moose likes Mock Exam Errata and the fly likes RHE Bonus1 Q49 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "RHE Bonus1 Q49" Watch "RHE Bonus1 Q49" New topic
Author

RHE Bonus1 Q49

Tony Xu
Greenhorn

Joined: Sep 27, 2001
Posts: 27
I searched and found one thread about this question. unfortunately, it's not a done thread. still need verification. http://www.javaranch.com/ubb/Forum35/HTML/000119.html
Question 49 from RHE Bonus1
/////////////////////////////////////////////
Consider the following class definition:
public class Parent {
final void zzz() { }
}
Which of the following methods may appear in a subclass of Parent, when the subclass is in a different package from Parent? Choose all correct options.
A) void zzz() { }
B) void zzz(int j) { }
C) final void zzz(float f) { }
D) public final void zzz(double d) { }
/////////////////////////////////////////////////
The answers given are BCD. Here is the given reason:
A final method may not be overridden; thus A is illegal. The methods in B, C, and D have different argument lists from the superclass version of the method, so B, C, and D are not examples of overriding; they are all legal.
Actually, I think A is also correct since the subclass is in a different package and the final void zzz() {} is with "default" access modifier, which means this method is invisible out side of the package where it lives. Hence, it's ok to have a method named void zzz() {} within a subclass in a different package.
Please clarify and verify me.
Nain Hwu
Ranch Hand

Joined: Sep 16, 2001
Posts: 139
Tony,
I agree with you - answer A is correct too.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Answer A is wrong since the method zzz is final and thus NOT OVERRIDABLE in any subclass !!!
The correct answers are BCD ass suggested since those are juts overloading zzz.
The method zzz is not INVISIBLE outside the package but just INACCESSIBLE ! This is really different.

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
[This message has been edited by Valentin Crettaz (edited October 01, 2001).]


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Nain Hwu
Ranch Hand

Joined: Sep 16, 2001
Posts: 139
Val,
How come I can compile the following code:

The question is not asking whether zzz() can be overriden.
It is asking which one can "apprear" in the subclass of Parent.
Java compiler does not complain the above code. So, I still
think A is correct.
But, I am not sure what relationship we can say between these
two zzz() methods. (sleepy head maybe)
Tony Xu
Greenhorn

Joined: Sep 27, 2001
Posts: 27
Thank you, Val. Now I understand the difference.
I want to test the answers, however, I cannot do it. When I import parentPackage.*, my JBuilder just tells it cannot find the package. Why? Anybody can help?
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Nain,
if you try to compile your code, there is no error, right but a WARNING message like the following,

So if the purpose is not overriding then it is ok you can discard the compiler warning, but only poorly-educated developer do so, smart one choose another method name to avoid trouble.
I still think that overrinding was n the author's mind but I'm not a mind reader so your argumentation holds and A may be correct too !

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
[This message has been edited by Thomas Paul (edited October 02, 2001).]
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Tony,
For such easy examples, why don't you just use the JDK and some DOS-Console (on Win) or Terminal (on Linux/UNIX)...
Anyway, you have 2 directories A and B, you can compile A alone since it does not depend on B, but when you compile B you should give a correct classpath to find the classes in package A like this (assume you are in directory B):
javac -classpath .. <class-in-B.java>
Note the classpath option !
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
Nain Hwu
Ranch Hand

Joined: Sep 16, 2001
Posts: 139
Val,
I totally agree with you on how to code wisely. It is just the
way this mock question that is driving me nuts.
BTW, what java compiler are you using? I am using jdk1.3.1
and it didn't have the same warning as yours.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: RHE Bonus1 Q49