Help the world stop coronavirus! Stay home!

Prev Next

Java / Enum

Can an enum have main method in Java?

Yes. enum can have startup main method that JVM executes.

public enum EnumExample {

	Ex1(1, 2), Ex2(2, 3);

	static enum InnerEnum {

	int val1, val2;

	EnumExample(int val1, int val2) {
		this.val1 = val1;
		this.val2 = val2;


	int myMethod() {
		return val1 + val2;

	static void myStaticMethod() {
		System.out.println("Enum static method");

	// abstract void myAbstractMethod() ;

	public static void main(String s[]) {

❤Cash Back At Stores you Love !!!❤

Earn your $10 reward when you make your first purchase through Ebates by signing up with clicking below button.

Ebates Coupons and Cash Back

More Related questions...

Show more question and Answers...


Comments & Discussions