Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in threading

 
Amit Batra
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi, in the above code,I made an anonymous inner class and defined the run method in it. But I didnt extends the thread class or implement runnable. how am I being able to to do? the code runs fine and prints hello.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amitabha Batranab:
I didnt extends the thread class or implement runnable.


Yes, you did. The anonymous inner class extends Thread.
 
Mandeep kaur
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anonymous class is created and instantiated at same time.it can be created from by extending any class or interface and extends keyword is never used. when made from a class its format is :-
new superclassName(argument list){
//Body of this class
};
So when you do this following things are done:-
1.constructor of superclass is called,If you dont specify any argument then the default constructor of superclass is called else the argument constructor corresponding to arguments you passede is called
2.Object of this anonymous class is crated using new.
when anonymous class is created from any interface as its supertype format is:
new interface name(){
//Body of this class
};

hope now the concept of anonymous class is clear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic