ADVERTISEMENT
ADVERTISEMENT

Java program to create the main() method inside the enum class

Java example to create the main() method inside the enum class.
Submitted by Nidhi, on April 04, 2022

Problem Solution:

In this program, we will create a vehicle enumeration class using "enum" that contains the main() method and access the created enum constants.

Program/Source Code:

The source code to create the main() method inside the enum class is given below. The given program is compiled and executed successfully.

// Java program to create the main() method 
// inside the enum class

public enum Vehicle {
  BIKE,
  CAR,
  BUS;

  public static void main(String[] args) {
    Vehicle car = Vehicle.CAR;
    System.out.println("Vehicle is: " + car);
  }
}

Output:

Vehicle is: CAR

Explanation:

In the above program, we created an enumeration class with constants and the main() method. Here, we created the object of enumeration class Vehicle and initialized it with CAR constant and printed the result.

Java Enums Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.