This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes enum within a class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "enum within a class" Watch "enum within a class" New topic
Author

enum within a class

Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

can we declare enum within a class.............

like

public class EnumTypeDeclarations
{
public void foo()
{
enum SimpleMeal {
BREAKFAST,LUNCH,DINNER
}
}
}


SCJP6.0,My blog Ranchers from Delhi
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2885
    
  13

phil sohan wrote:can we declare enum within a class

What happened when you tried that?
Also, please UseCodeTags.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
My Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Your code actually asks a different question than your text: your code is asking whether or not you can define an enum within a *method*.
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

can we declare enum within a class.............

like

public class EnumTypeDeclarations
{
public void foo()
{
enum SimpleMeal {
BREAKFAST,LUNCH,DINNER
}
}
}


I have seen this question somewhere in mock test of scjp1.6(not known where)
but i am really confused about it.........as of now i have seen enum is declared as seperate from class......
could you please tell whther its possible to declare it ornot,,,,,,
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2885
    
  13

phil sohan wrote:could you please tell whther its possible to declare it ornot,,,,,,

Devaka Cooray wrote:What happened when you tried that?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18101
    
  39


Devaka Cooray wrote:What happened when you tried that?


Agreed. It has been over 2 hours since the original post. Trying it yourself would have taken under a minute.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And again, please note the difference between what you're asking in text and what your code is trying to do.

(I also think either your keyboard or keyboard driver is broken as you punctuation keys seem to repeat.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: enum within a class
 
Similar Threads
Extending a enum with enum's type
Enum doubt
enums
Enums and access
Enum example