wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Questions from John Hunt mock 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 "Questions from John Hunt mock" Watch "Questions from John Hunt mock" New topic
Author

Questions from John Hunt mock

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Could someone please explain to me about the following questions?
public class Test {
static int total = 10;
public static void main (String args []) {
new Test();
}
public Test () {
System.out.println("In test");
System.out.println(this);
int temp = this.total;
if (temp > 5) {
System.out.println(temp);
}
}}
A the class will not compile;
B the compiler reports and error at line 2
C the compiler reports an error ate line 9
D the value 10 is one of the elements printed to the standard output
E the class compiles but generate a runtime error.
Given answer is C, but I have run this. No compile and runtime error reported. The results is:
In test
Test@7315cf7d
10
So i think the right answer might be D.
I will appreciate if some one can explain this to me.
Thanks
Surya B
Ranch Hand

Joined: May 10, 2000
Posts: 98
Hi
The answer as you have pointed out is D.
Surya
Karthik Subramanian
Greenhorn

Joined: Aug 23, 2000
Posts: 27

Hi all,
Does this mean that 'this' cannot be used on
static methods but can be used on static variables.
Can somebody throw some light??
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Questions from John Hunt mock
 
Similar Threads
q on testonline.com
Static variable
Using this to reference static variables
Access to static variable
John Hunt M.E Q17