This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

R&H bonus1 q49

 
nan s
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question:
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?
a) void zzz{}
b) void zzz(int j){}
c) final void zzz(float f){}
d) public final void zzz(double d){}
they have Answer is b,c,d
But I wonder subclass is in different package with Parent,
so subclass can not see final void zzz() in Parent,
because zzz() is "default", so i think there is no overridding here.
where i am wrong?
 
rajani peddi
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nan ,
The answers are correct and your understanding is also correct.
First of all option a) is wrong because it is neither a valid method nor a variable.
Now Since the method zzz() in superclass has package visibility it is not known to its subclass which is in another package. So the methods in subclass can neither overload nor override. Hence the subclass can have any valid method. Infact it can also have final void zzz() {}.
Hope this clears
rajani

[This message has been edited by rajani peddi (edited January 05, 2001).]
 
nan s
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry rajani and all,
I have a typing error about this bloody "a) void zzz{}", i checked again, IT IS "void zzz(){}", and their explanation of why "a" is incorrect as: "A final method may not be overridden, thus A is illegal."
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?
a) void zzz(){}
b) void zzz(int j){}
c) final void zzz(float f){}
d) public final void zzz(double d){}
they have Answer is b,c,d
i am sorry for error.
nan
 
nan s
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry rajani and all,
I have a typing error about this "a) void zzz{}", i checked again, IT IS "void zzz(){}", and their explanation of why a is incorrect as: "A final method may not be overridden, thus A is illegal."
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?
a) void zzz(){}
b) void zzz(int j){}
c) final void zzz(float f){}
d) public final void zzz(double d){}
they have Answer is b,c,d
i am sorry for error.
nan
 
nan sh
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry rajani and all,
I have a typing error about this "a) void zzz{}", i checked again, IT IS "void zzz(){}", and their explanation of why a is incorrect as:"A final method may not be overridden, thus A is illegal."
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?
a) void zzz(){}
b) void zzz(int j){}
c) final void zzz(float f){}
d) public final void zzz(double d){}
they have Answer is b,c,d
i am sorry for error.
nan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic