aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes simple question 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 "simple question" Watch "simple question" New topic
Author

simple question

JayaSiji Gopal
Ranch Hand

Joined: Sep 27, 2004
Posts: 303
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);
}}}

The compiler reports an error at line 2
The class will not compile
The value 10 is one of the elements printed to the standard output
The compiler reports an error at line 9
The class compiles but generates a runtime error

i answered the 4th option,but the correct answer is 3.
i answered 4th, bcos static variables cannot have a this reference.

plz correct me, wht is wrong?


SCJP 1.4, SCWCD 1.4<br /> <br />Thanks in advance!<br />Jayashree.
Aneesha Singh
Ranch Hand

Joined: Jan 14, 2002
Posts: 47
Originally posted by JayaSiji Gopal:
public class Test {
static int total = 10;
public static void main (String args []) {


At this point, you created an instance of teh class Test. This action invoked the constructor. So when you refer to this in the constructor, you refer to teh class created here. So the 3rd option is indeed correct.
Hope that helps.


new Test();
}
public Test () {
System.out.println("In test");
System.out.println(this);
int temp = this.total;
if (temp > 5) {
System.out.println(temp);
}}}

The compiler reports an error at line 2
The class will not compile
The value 10 is one of the elements printed to the standard output
The compiler reports an error at line 9
The class compiles but generates a runtime error

i answered the 4th option,but the correct answer is 3.
i answered 4th, bcos static variables cannot have a this reference.

plz correct me, wht is wrong?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: simple question