Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Doubt about java program execution without class

 
Greenhorn
Posts: 6
Oracle Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 76474
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>.
 
That's a very big dog. I think I want to go home now and hug this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic