A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

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

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now