• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

enum on OCA exam objectives

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm wondering as whether enum is still on the objective topic of the OCA since I don't see Sybex mention this.
 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most likely questions regarding enum will not be on the Java 808 OCA exam.
That said, for the OCA level of questions, enums can be thought of as final classes.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Pete Letkeman, Sorry for my greenhorn arrogance but are you sure that an enum class can be final?  (of course enums themselves are always final)

https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.9
"It is a compile-time error if an enum declaration has the modifier abstract or final."
 
Marshal
Posts: 79978
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
What is the difference between an “enum class” and an enum? Pete said that enums are final classes, which matches what the Java® Language Specification says.
 
Sheriff
Posts: 28331
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.9

"It is a compile-time error if an enum declaration has the modifier abstract or final.
An enum declaration is implicitly final unless it contains at least one enum constant that has a class body (§8.9.1)."
 
author & internet detective
Posts: 42024
916
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Enums are on page 72 of the Sybex 1Z0-808 book.
 
Teodor Ian
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much, now I understand.
The misunderstanding was that English is not my mother tongue and I translated in my head: "enum can be thought of as a final class".
 
Campbell Ritchie
Marshal
Posts: 79978
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quoting from the JLS link given earlier.

Paul Clapham wrote:. . . An enum declaration is implicitly final unless it contains at least one enum constant that has a class body (§8.9.1)."


I think I misunderstood that bit about implicitly final at first. I thought that meant that an enum with class bodies can be extended by a different XXX.java file or compilation unit. I think it actually means that enums with class bodies extend themselves. They cannot be extended elsewhere. The constants with class bodies look like instances of anonymous classes. I don't know whether they really are anonymous classes.
If you write a compilation unit extending an enum with class bodies for every constant, e.g. the Operation enum from the Java™ Language Specification (=JLS), you will see you get a compiler error.
If you go through the first JLS link I gave you, you will find out why you can't write enum XYZ extends...
 
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic