Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About anonymous inner class!

 
Tony Sam
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi here,
Could a anonymous inner class have its own constructor ? if yes, could someone give me a sample about this, Some books say Yes,others say No. i am really really confused ...
Thanx in advance
 
Hussain
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi sam,
no const in annonemus class
but
a
intilize block
like this:
new Ann()
{
{
System.out.println("A");
}
};
------------------
Muhammad Hussain
 
Nain Hwu
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony,
Just think why it is called "anonymous"?
It has no name and a constructor must have the same name as
its class. So, it is impossible to have a constructor for an anonymous class.
 
Uma Viswanathan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot have constructor for anonymous inner class but if the parent class have constructors,then we can arrange to invoke one of the parent class constructors by passing the appropriate arguments...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic