• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Annoymouse class always require ;(semi colon)  RSS feed

 
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??
 
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....
 
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
 
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!