jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dan's mock exam#1 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 "Dan Watch "Dan New topic
Author

Dan's mock exam#1

Deep Chand
Ranch Hand

Joined: Dec 17, 2002
Posts: 133
Hi,
First of all, I just wanted to verify that Dan's famous exams are available from
this link: http://www.danchisholm.net/apr18/comprehensive/index.html.
i.e. I just wanted to make sure that I'm attempting the right exams?
2) I gave the first mock exam. I have 2 doubts.
a) Like, what should be the decent score on these mock exams. For e.g.
I got 26/31. Is it decent or really bad? What's the difficulty level
of the real exam compared to those exams?
b) Although I ran the program and verified that the answer is correct
but I can't understand why? In the following code,
why the printS1() of class P is invoked? I thought the context is an object
of class Q. So shouldn't Q's printS1() should be invoked? I know the difference
between static hidden methods and instance overriden methods but still here
we are not invoking the method using reference of type P. If we were invoking
by using P p = new Q() and then p.printS1S2() then I had no problems but ???

Question 25 (mock exam#1):
UBB code
class P {
static void printS1(){System.out.print("P.printS1 ");}
void printS2() {System.out.print("P.printS2 ");}
void printS1S2(){printS1();printS2();}
}
class Q extends P {
static void printS1(){System.out.print("Q.printS1 ");}
void printS2(){System.out.print("Q.printS2 ");}
public static void main(String[] args) {
new Q().printS1S2();
}
}

What is the result of attempting to compile and run the above program?
ans rints: P.printS1 Q.printS2

Thanks,
Deep
Uma Balu
Ranch Hand

Joined: Aug 22, 2003
Posts: 61
Hi,
Since the method printS1S2() is declared in the base class, the call to the static method printS1() will invoke only the base class static method, since the re-declared method printS1() is hidden(not known to the base class) from the base class method printS1S2().
Try overriding the method printS1S2(), in the derived class. It will invoke only the derived class's static method, since the base class method is obviously hidden. Hope my understanding is right.
Regards,
Uma....
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Deep: I just wanted to make sure that I'm attempting the right exams
Yup, you're on the right track
Deep:
2) I gave the first mock exam. I have 2 doubts.
a) Like, what should be the decent score on these mock exams. For e.g.
I got 26/31. Is it decent or really bad? What's the difficulty level
of the real exam compared to those exams?

my $0.02, if you're getting consistently more than 60-65% you're ready for the exam.

My explanation: You're creating an instance of class Q and invoking printS1S2() method.
void printS1S2(){printS1();printS2();}
Notice that printS1() is a static method, and static methods are not overriden. So, even if you have a method with the same name in the subclass, it's definitely not overriden, just happen-to-have the same name. Therefore, P.printS1 of class P will be used.
Looking at printS2(), we can see that the method is overriden, so the method to use is the one defined in class Q.
hope it helps


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dan's mock exam#1