• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help on Enum problem

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what will be the right answer for following problem

note: illegal posting of copyrighted material deleted - Bert
[ August 07, 2007: Message edited by: Bert Bates ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See Enums.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
4,3,1,5,2

enum XXZ{

X,Y,Z(var){ return something;}

XYZ(Type var){
return nothing;
}

}; // Compulsory when having Constant Specific Body.
 
kishore Kumar Sangam
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for confusion it is 43215
 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As you can see FIRE defines a anonymous inner class that extends enum Element which is called constant specific class body and overrides info(), Its not that the constant specific class body must end with a semicolon,

>>> illegal material edited <<<

So with the above code there can be many answers to the question.


Thanks
Deepak

[ August 04, 2007: Message edited by: Deepak Jain ]
[ August 07, 2007: Message edited by: Bert Bates ]
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Deepak Jain:
...there can be many answers to the question...


I see only one correct answer. (And your code does not compile.)
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>>> code edited out <<<

For the given set of answers there is only one correct answer, The point I am trying to stress is "; is a must, not because FIRE{} is constant
specific class body but because the every staement must end with a ;"


Thanks
Deepak

[ August 07, 2007: Message edited by: Deepak ]
[ August 07, 2007: Message edited by: Bert Bates ]
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Deepak:
; is a must

This is not true in general. The semicolon is only required if you have additional code after the constant declaration.

>>> code removed <<<
[ August 07, 2007: Message edited by: Bert Bates ]
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Manfred.
But what about method declaration in enum before declaring the constants why does it give a compiler error
 
Manfred Klug
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Deepak:
But what about method declaration in enum before declaring the constants why does it give a compiler error

It's defined this way by the language designers.

For the full details have a look at 8.9 Enums in the Java Language Specification
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike Anakin,

please check your private emails by clicking "My Profile" near the top of the page.


Yours,
Bu.
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this was a real exam question - therefore illegal to possess!

Please do not post, or traffic illegally obtained, copyrighted material.
 
a wee bit from the empire
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic