This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
The moose likes Certification Results and the fly likes Dan's single topic-anonymous classes. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Certification » Certification Results
Bookmark "Dan Watch "Dan New topic
Author

Dan's single topic-anonymous classes.

Jui Mahajan
Ranch Hand

Joined: Jun 02, 2003
Posts: 62
In his single topic exams, Dan says that anonymous classes cannot be static. But in the following example (which is also from the same exam), the anonymous class is static and the example compiles. How ?abstract class A {
private int x = 4;
private int y = 2;
public A(int i1) {x=i1;}
public int x() {return x;}
public void x(int x) {this.x = x;}
public int y() {return y;}
public void y(int y) {this.y = y;}
public void incY() {y++;}
public abstract int math();
}
class B {
static A a1 = new A(2) {
{incY();}
public int math() {return x()+y();}
};
public static void main(String[] args) {
System.out.print(a1.math());
}
}


-----jui<br />scjp1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dan's single topic-anonymous classes.