K
K
Koshkasobaka2020-11-13 12:49:29
Java
Koshkasobaka, 2020-11-13 12:49:29

How to set fields for Enum?

Help, please, I'm creating a class Fruit, which has fields - fruit type enum and weight. The type of fruit must have a field - a fixed price per kg. How to create a field inside an enum?

public enum Fruit {

   APPLE,
   ORANGE,
   BANANA,
   PEAR;

 
public int getEight() {
      return eight;
   }
   public void setEight(int eight) {
      this.eight = eight;
   }


   private int eight;

  Fruit(int eight) {
      this.eight = eight;
   }

 

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Roo, 2020-11-13
@Koshkasobaka

https://javarush.ru/groups/posts/1963-kak-ispoljhz...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question