• 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 bouns1-49

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 Answer was given as B,C,D
I wonder, as void zzz() in Parent can not be seen
in subclass, why subclass can not have another void zzz()?
what about take away final acess modifier in Parent class?
Anyone could explain?
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The final keyword in a method declaration indicates to the compiler that the method cannot be overridden by
subclasses.Hence choice A is incorrect.
If you take away the final access modifier from the method i think all A,B,C,D would be valid choices.
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi nan,
what is this R&h1-49 ??are these some kind of sample Q&A or a mock?please tell
thank you
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think A is a correct answer - I tried this out and it will compile.
Nan's point is valid - the method has 'default' access and so will not be visible to subclasses in a different package. So declaring a method with the same signature in the subclass should be OK - it does not actually override the parent's method, since this will not have been inherited.
 
nan sh
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question from R&H book( our Bible!). There are three Bouns Mock tests and one final test. The question is from Bonus 1 q49.
 
nan sh
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have run the following code, it print out
"in B zzz", that means given answer is wrong!
Moderator, could you move this thread to Mock Exam errata forum please.
//file B.java
import pack1.*;
public class B extends A{
void zzz(){System.out.println("in B void zzz");}
public static void main(String[] args){
A a = new B();
B b = new B();
A a1 = new A();
// a.zzz(); compile error
b.zzz();
// a1.zzz(); compile error
}

//package pack1;
package pack1;
class A{
final void zzz(){System.out.println("in A void zzz"); }
}//
 
preeti dengri
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi nan,
that's a good catch! keep it up.
i have got RHE book but the cd alongwith doesnot contain the three bonus mock tests and one final test u are talking about.so if possible cud u please mail me all those at preetidengri@yahoo.com.
thank you
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have the CD with bunus ques. but i am not able to run the tests.after some questions(5 or so) my machine hangs up!what's the problem.i have loaded them and then tried but same problem is coming?is it something to do with my machine?
please help.
 
preeti dengri
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
i have got the older version of RHE so i need ur help .please if possible,mail me the all three mock tests and a final test given with RHE latest edition at preetidengri@yahoo.com
waiting for an early reply
thank you
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic