• Post Reply Bookmark Topic Watch Topic
  • New Topic

Annoymouse class always require ;(semi colon)  RSS feed

 
appu sharma
Ranch Hand
Posts: 104
Java Netbeans IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is code first

and second
so whyn't there is semicolon in first code it is also a annoymouse class??
 
Brij Garg
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have combined two statement in one statement in first code.There is just one statement and so one ;
 
appu sharma
Ranch Hand
Posts: 104
Java Netbeans IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brij Garg wrote:You have combined two statement in one statement in first code.There is just one statement and so one ;

but what is the syntax of annoymouse class??? it inlude semi colon....
 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have to combine two operation - creation of object and calling the method then it will be treated as a single entity like



Here you do not have to place a semicolon between test() and doSomething() method.

The same way while declaring an anonymous class you can combine the two operation in one unit and you have to write a single semicolon at the end of the statement.

Remember - Semicolon represents "End Of The Statement"
 
Brij Garg
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here you have to give two semicolons as the object creation is one statement and calling the method is another statement.
But for,

you need only one semicolon as you have done the two in the same statement.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!