File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Understanding method declarations created with Object ob = new Object(){ ... };

 
Ehsan Rahman
Ranch Hand
Posts: 59
Chrome Netbeans IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
John de Michele
Rancher
Posts: 600
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 59
Chrome Netbeans IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic