Total members 11889 |It is currently Thu Mar 28, 2024 4:53 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Extending enum in java. Can we extend (inherit) an enum type.
extending enums in java is not allowed. As example suppose you have two enums A and B .Y
You can't do the following :

Code:

enum B
{
}
enum A extends enum B
{
   // Define you enum here .
} 



And in the same time you can't use implements keyword , because B is not an interface ,But if your system need both to be same type , for example if you want to define one function signature to take both enums as parameters you can do it by defining an enum and implementing it in both enums .

Code:

interface enuminterface
enum B implements enuminterface
{
}
enum A  implements enuminterface

{
   // Define you enum here .
} 


and your signature will be something like this :
Code:
 return type myfunction (enuminterface Enumparam)  ;  




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : extending enum in java
 Java extending org.apache.log4j.Logger     -  
 Java enum example     -  
 Define enum in java     -  
 Extending Quartz Scheduler Job Interface     -  
 Enum Declaration     -  
 how to use enum in jaxb unmarshalling     -  
 Define Enum inside a class     -  
 Passing Enum as Type Parameter to method     -  
 2d game in java-Monster-Java 2D Game Graphics and Animation     -  
 java or .net     -  



Topic Tags

Java OOP
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com