This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Enum - Constant Specific Body Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Enum - Constant Specific Body" Watch "Enum - Constant Specific Body" New topic

Enum - Constant Specific Body

Jisha Anand
Ranch Hand

Joined: Apr 02, 2009
Posts: 62

Dear All,

Enum is again troubling me

I have seen that we can overload a method in enums. Also, I have seen that we can define a method in an enum and overload the method (change the args) in constant specific body. This compiles fine. But when I try to call the method defined in consant specific body the compiler complains. Why is this so?

The following is my code. The line in bold creates the issue

public enum Seasons {

public int getSeasonValue() {
return 100;
public int abc = 1999;
public int getSeasonValue(int x) {
return 20;

private int seasonValue;

Seasons(int x) {
seasonValue = x;

Seasons() {

public int getSeasonValue() {
return seasonValue;
public static void main(String args[]) {
Season season = new Season();
System.out.println("SUMMER: "+season.seasonS.getSeasonValue());
System.out.println("WINTER: "+season.seasonW.getSeasonValue());
System.out.println("AUTUMN: "+season.seasonA.getSeasonValue(10));

class Season {
Seasons seasonS = Seasons.SUMMER;
Seasons seasonW = Seasons.WINTER;
Seasons seasonA = Seasons.AUTUMN;

Ankit Garg

Joined: Aug 03, 2008
Posts: 9291

Well the answer is simple, the methods that you define in enum specific body are like methods in anonymous inner classes. So you can only call the methods available in the enum just like you can only call the methods available in the super class of an anonymous inner class

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Jisha Anand
Ranch Hand

Joined: Apr 02, 2009
Posts: 62

Got it; thanks a lot Ankit..

Even if the method is declared public there is no way to access the method outside the class..same with enum right?
Rob Spoor

Joined: Oct 27, 2005
Posts: 19656


How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Enum - Constant Specific Body
Similar Threads
Changing String Value (if and else statements
Enum Issue
enum - need help
Since Enums are static, could I use either static import or regular import on them
Simple J2SE 5.0 Tiger Notes