Two Laptop Bag*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes from RHE Bonus Questions 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 "from RHE Bonus Questions" Watch "from RHE Bonus Questions" New topic
Author

from RHE Bonus Questions

Sathi Chowdhury
Ranch Hand

Joined: Mar 16, 2001
Posts: 52
This is from Rhe book's bonus question set...
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) { }
I thought all are correct because since the subclass is out side the package so the zzz() method of parent is not accessible from the subclass.
but the answer is given B,C,D which are very obvious ,but i have a doubt that A also is correct...can anybody explain me the right thing
thank u
Daniel Dunleavy
Ranch Hand

Joined: Mar 13, 2001
Posts: 276
I should think it would be that final does not change what is returned or what is passed to method.
Dan
mousami bhattacharya
Ranch Hand

Joined: May 13, 2001
Posts: 40
Sathi,
I agree with you , even I thought it to be all options .
I checked out by writing the code.and we are correct.
If a subclass is in a different package ,then the default method in parent is not accessible to the subclass and we can provide the same method signature with a more restricting accesibility .It just gives a warnign during compile time.
So the answer should be all 4
Mousami
Charlie Swanson
Ranch Hand

Joined: Jan 29, 2001
Posts: 213
Sathi,
I entered the below code and it ran fine. You are right about
option A.
<CODE>
package mypack1;
public class Parent {
final void zzz() {
System.out.println("zzz");
}
}
//File: Child.java
package mypackage;
import mypack1.*;
public class Child extends Parent {
void zzz() {
System.out.println("child zzz");
}
public static void main(String args []) {
new Child().zzz();
}
}
</CODE>
 
Don't get me started about those stupid light bulbs.
 
subject: from RHE Bonus Questions
 
Similar Threads
RHE mock question bonus1 q49
R&H bonus1 q49
Package and Overriding
RHE Bonus1 Q49
R&H bouns1-49