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 access enum constants using \'for each\' loop
Q:

Java program to access enum constants using \'for each\' loop

0

Java program to access enum constants using 'for each' loop

All Answers

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

Program/Source Code:

The source code to access enum constants using "for each" loop is given below. The given program is compiled and executed successfully.

// Java program to access enum constants 
// using "for each" loop

public class Main {
  enum Vehicle {
    BIKE,
    CAR,
    BUS
  }

  public static void main(String[] args) {
    Vehicle arr[] = Vehicle.values();

    for (Vehicle v: arr) {
      System.out.println(v + " at index " + v.ordinal());
    }
  }
}

Output:

BIKE at index 0
CAR at index 1
BUS at index 2

 

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