Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4616250
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:57:18+00:00 2026-05-22T01:57:18+00:00

enum Enum1 { BIG(8), HUGE(10) { public String getName() { return Huge; } public

  • 0
enum Enum1
{
    BIG(8), HUGE(10)
    {
        public String getName()
        {
            return "Huge";
        }

        public String getContry()
        {
            return "India";
        }//additional Method
    },
    OVERWHELMING(16)
    {
        public String getName()
        {
            return "OVERWHELMING";
        }
    };
    private int ounces;

    public int getOunes()
    {
        return ounces;
    }

    public String getName()
    {
        return "Ponds";
    }

    Enum1(int ounces1)
    {
        ounces = ounces1;
    }
}

class EnumAsInnerClass
{
    Enum1 enumInnerClass;

    public static void main(String[] args)
    {
        EnumAsInnerClass big = new EnumAsInnerClass();
        big.enumInnerClass = Enum1.BIG;
        EnumAsInnerClass over = new EnumAsInnerClass();
        over.enumInnerClass = Enum1.OVERWHELMING;
        EnumAsInnerClass huge = new EnumAsInnerClass();
        huge.enumInnerClass = Enum1.HUGE;
        System.out.println(big.enumInnerClass.getName());//Ponds        
        System.out.println(over.enumInnerClass.getName());//OVERWHELMING
        System.out.println(huge.enumInnerClass.getName());//Huge
    }
}

Consider the above example. How can I call the method getCountry for HUGE?

If there is no way to call this method, why does Java treat it as legal?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:57:19+00:00Added an answer on May 22, 2026 at 1:57 am

    (As noted nearly 4 years later, my original answer was incorrect.)

    You can’t even call Enum1.HUGE.getCountry() with the specific enum, which is very slightly surprising… but even if you could, you couldn’t do so with an arbitrary Enum1 value, which would be more generally useful.

    The solution is to stop it from being an additional method – add a getCountry() method into Enum1, either returning a default value or maybe throwing an exception. HUGE can then override the method.

    It would be nice if you could declare that a particular enum value implemented an interface, but it seems there’s no syntax for that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class Coffee{ enum CoffeeSize{BIG,HUGE,OVERWHELMING} CoffeeSize size; } class CoffeeTest{ public static void main(String[] args)
I have the following enum: public enum Status implements StringEnum{ ONLINE(on),OFFLINE(off); private String status
Given the following java enum: public enum AgeRange { A18TO23 { public String toString()
i have enum public enum TypeImage { Img=0, Thumb=1 } i want in view
I have an enum public enum FileExtentions { mp3, mpeg } And I have
I want to implement an extension method which converts an enum to a dictionary:
We use one big enum for message passing and there are optional parts of
How can I cast a value from Enum1 to Enum 2 in Java? Here
Possible Duplicate: Is there a simple script to convert C++ enum to string? In
namespace ValueType { enum Enum { Boolean = 0, Float = 1, Double, SInt

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.