• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

R&H bonus1 q49

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic