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

JAVA BEGGINER

 
Ar Yasoda
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why semicolon in java is not compulsory where as in c++ it is required after the completion of any class.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll move this to our beginners forum for you.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49776
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

The position and presence and absence of semicolons in languages is not fixed by some law. It depends what the designers of the language thought and how they constructed the compiler. Different languages have semicolons in different places.

CR
 
Ar Yasoda
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for replying......
but how can jvm can know that the class has been ended..
 
Srikanth Ramu
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess it should be by } - curly brace
 
Campbell Ritchie
Sheriff
Pie
Posts: 49776
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look in the Java Language Specification section 18.1; push ctrl-F then classBody. You will find:
ClassBody:
{ {ClassBodyDeclaration} }
So the compiler works out the end of the class body by counting { and }. Exactly as srikanth ramu said.
[ April 04, 2007: Message edited by: Campbell Ritchie ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic