• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Enum Doubts

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can any one explain me why I cant declare getMark() method abstract in following code on line 1 .

Thanks in advance.
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


you can't declare getMark() as abstract, which belongs to enum Grade because::

enums are final so you can't extend them..hence marking getMark() as abstact means you have to create a sub-class of enum Grade which you obviously cannot..

remember enums are implicitly final and static (though static here has nothing to do with methods cannot be abstract, but because enums are static, to import them you can use import static.... just for knowledge)


[ August 08, 2007: Message edited by: Priyam Srivastava ]
 
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 Priyam Srivastava:
you can't declare getMark() as abstract


You can declare getMark() as abstract. But as result, every enum value must implement this method.

remember enums are implicitly final and static

Small reminder. Enums are only static if they are declared inside another class.
 
I AM MIGHTY! Especially when I hold this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic