This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Ques from John Hunt's Mock Exam 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 "Ques from John Hunt Watch "Ques from John Hunt New topic

Ques from John Hunt's Mock Exam

Murtuza Akhtari
Ranch Hand

Joined: Aug 07, 2004
Posts: 108
hey guys
can sum1 tell me how do we choose a proper answer for this question

What is the result of compiling and running this class?

A.The string Test is printed to the standard out.
B.A runtime exception is raised stating that an object has not been created.
C.Nothing is printed to the standard output.
D.An exception is raised stating that the method test cannot be found.
E.An exception is raised stating that the variable this can only be used within an instance.
F.The class fails to compile stating that the variable this is undefined.
Select all correct answers

The correct answer given is F...However even E looks pretty much acceptable because whn I tried to compile and run the program the exact error I got was

non-static variable this cannot be referenced from a static context
So neither of the answers had the exact match how do we choose the proper answer ??

---<br />SCJP 1.4
kavya krushi
Ranch Hand

Joined: Oct 25, 2000
Posts: 48
Exceptions occur during runtime ... So i dont think the usage of the word "exception" in option E makes it a correct choice. Since option F clearly states that it is a compiler error, i would stick with that ...
Aarti Dahiya

Joined: Aug 07, 2004
Posts: 15

The this reference (ie the reference to the current executing object) is NOT implicitly passed to a static method. Since, a static method is not tied to a specific instance of a class. It results in a compile time eror.

SCJP 1.4 (95%)
kapil munjal
Ranch Hand

Joined: May 11, 2004
Posts: 298

I agree with Aarti that it will throw a compile time error because of 'this'
being used on a static method.


Kapil Munjal
SCJP 1.4, SCWCD 1.4
I agree. Here's the link:
subject: Ques from John Hunt's Mock Exam
It's not a secret anymore!