| Author |
Understanding method declarations created with Object ob = new Object(){ ... };
|
Ehsan Rahman
Ranch Hand
Joined: Feb 16, 2009
Posts: 59
|
|
Hi All,
This is probably an easy one ...
Why is it that if line 5 is commented out then the method in 11 is not applicable (and results in a compiler error), even though it does override as the code is above.
I've noticed this type of over-ride used a lot with the run() method when creating Threads.
Many Thanks,
Ehsan
|
SCJP 1.5, SCJD 1.6
|
 |
John de Michele
Rancher
Joined: Mar 09, 2009
Posts: 600
|
|
The @Override annotation lets the compiler know that you're overriding or implementing a method in a superclass. By commenting out the original method, you're no longer overriding it in your anonymous subclass.
John.
|
 |
Ehsan Rahman
Ranch Hand
Joined: Feb 16, 2009
Posts: 59
|
|
Thanks. Yes, it is an anonymous class.
http://docstore.mik.ua/orelly/java-ent/jnut/ch03_12.htm
Syntax: new class-name ( [ argument-list ] ) { class-body }
http://www.coderanch.com/t/409946/Java-General-beginner/java/call-method-anonymous-class
|
 |
 |
|
|
subject: Understanding method declarations created with Object ob = new Object(){ ... };
|
|
|