File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes this(a) 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 "this(a)" Watch "this(a)" New topic
Author

this(a)

Ideal Me
Greenhorn

Joined: Mar 11, 2001
Posts: 5
I'm very confused by the compilation error: can't reference a before the supercalss constructor has been called.
please read the following code and I look forward to explaination.
class Test {
int y=1;
int a=6;
Test() {
this(a); /* Complilatrion error: can't reference a before the supercalss constructor has been called. However, when I added the "static" modifier before the declarion "int i=6;", the program works ok. */
}
Test(int x) {
if ( x > y )
a = y*6;
else
a = y*9;
a++;
System.out.println(a);
}
public static void main(String [] args) {
Test t = new Test();
}
}
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
You can read
Test Your Java Knowledge, Question 12 for very good detailed explanation.

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: this(a)