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

  • SEARCH
  • Home
  • 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 8148843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:43:33+00:00 2026-06-06T14:43:33+00:00

The first one is enum class enum coffeeSize{ BIG(8), HUGE(10), OVERWHELMING(16); private int ounces;

  • 0

The first one is enum class

enum coffeeSize{
    BIG(8), HUGE(10), OVERWHELMING(16);
    private int ounces;
    coffeeSize(int ounces ){
        this.ounces = ounces;
    }
    public int getOunces(){
        return ounces;
    }

}

This is class CoffeeTest1 and main

 public class CoffeeTest1 {
      coffeeSize size;

      public static void main (String args[]) {
          CoffeeTest1 drink1 = new CoffeeTest1();
          drink1.size = coffeeSize.BIG;

          System.out.println(" " + drink1.size.getOunces());
      }
}

The below is output

8  

My question :
I don’t understand the how drink1.size.getounces() manage to output 8. I haven’t given constructor coffeeSize(8) object (ex: coffeeSize somex = new coffeeSize(BIG)). I want to know this simple subtle logic behind. Can someone help me understand please?

  • 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-06-06T14:43:34+00:00Added an answer on June 6, 2026 at 2:43 pm

    I dont understand the how “drink1.size.getounces() ” manage to output 8.

    […]

    I want to know this simple subtle logic behind.

    To understand the logic behind this, you can think of your enum as a regular class (which is actually how it is compiled), and

    BIG(8)
    

    as an instance of this class similar to

    new coffeesize(8);
    

    It should now be clear why drink1.size.getOunces() prints 8: BIG is just an instance of the coffeesize enum, for which you set ounces to 8 when constructing it.

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

Sidebar

Related Questions

I have two arrays the first one has this structure Parameter Keys array array
I've made the following test code: public enum Test { One = 1, Two
I am using an enum singleton that looks (somewhat) like this: public enum mySingleton{
I have the following Enum: Public Enum myEnum As Integer first = &H1 second
In java <1.5, constants would be implemented like this public class MyClass { public
CS. public abstract class Customer { public int Id { get; set; } public
I have defined an enum structure like this class myC { enum accessClass {
I've got an enum type defined in the private section of my class. I
class Game { public: static void Start(); private: static bool IsExiting(); static void GameLoop();
public enum FOO{ TATA(TOTO,TITI); public FOO(BAR bar1,BAR bar2) { bar1.associate(this,bar2); } } public enum

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.