Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

classes

 
lakshmi suji
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in classes syntax at the last can we give a semicolon
if we give then will it show any error or not?
ex:
class Example
{
};
 
ganesh pol
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why don't u compile it and see by the way i think u are talking about anonymus classes
 
Philip Heller
author
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The class definition ends at the closing curly bracket. The compiler thinks the semicolon marks the end of an empty statement. So you could even have:

which is a class definition followed by 10 empty statements.

The class is not necessarily inner.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Empty statements are almost always perfectly harmless.

I heard of a shop where programmers were rated by lines of code per month. The program that counted lines was not very smart, and people started decorating comment blocks like:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic