This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dan's ques - anonymous class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Dan Watch "Dan New topic
Author

Dan's ques - anonymous class

Shilpi M Ag
Ranch Hand

Joined: May 07, 2004
Posts: 40
what's going on here.. can someone please explain -
http://www.danchisholm.net/dec20/topic/section1/anonymous1.html

Question 3
abstract class A {
private int x = 4;
private int y = 2;
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 abstract int math();
}
class B {
static A a1 = new A(2,1) {
public A(int i1, int i2) {x(i1);y(i2);};
public int math() {return x()+y();}
};
public static void main(String[] args) {
System.out.print(a1.math());
}}
What is the result of attempting to compile and run the program?
a. Prints: 8
b. Prints: 3122
c. Compile-time error
d. Run-time error
e. None of the above

and is

3 c Compile-time error An anonymous class declaration can not contain an explicit declaration of a constructor.
Ana Abrantes
Ranch Hand

Joined: Sep 04, 2003
Posts: 43
Since an anonymous class doesn't have a name, it can't have a constructor, because constructors have the same name as the class.


Ana<p>SCJP 1.4
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Check this out.


SCJP Tipline, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dan's ques - anonymous class
 
Similar Threads
Dan's single topic-anonymous classes.
anonymous classes
Dan's questions
Inner class question from Dan's exam
abstract class instantiation