This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt about java program execution without class  RSS feed

 
sanyasirao nali
Greenhorn
Posts: 6
Java Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got a doubt regarding enum keyword

i wrote a code like below:

enum Program
{
;
public static void main(String[] args)
{
System.out.println("Program executed without class");
}
}

In java everything within a class But here i used enum keyword.This program successfully executed so what is the reason behind that?
and this program executed only with put semicolon(;) after first curly braces
My doubt is How this program executed and give reason anyone.

Thanks in advance
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An enum is a special kind of class.

An enum starts by listing the enum values, then there's a semicolon, then the rest of the enum body. In your case, you listed zero enum values, and then there's the semicolon to indicate the end of the value listing.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the tutorial:
The enum declaration defines a class (called an enum type).


Perhaps there are more details in JLS that someone else can point you to.
 
Campbell Ritchie
Marshal
Posts: 55711
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kemal Sokolovic wrote: . . . Perhaps there are more details in JLS . . .
Yes, there are. I think tou will need to follow the link to Enum<E>.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!