Thursday, June 25, 2009

All about enums:How to create ,How to use -- part 2

In part 1 we have see we can use the enums in two ways
1.As own class.
2.Within other class.

You can understand the usage in followin examples:-

=>Declaring enum as own class and outside the class:-

enum Processor{ P4,DUALCORE,COREDUO};

class Processorvalue{
Processor process;
}

public class Processortest{
public static void main(String a[]){
Processorvalue pval=new Processorvalue();
pval.process=Processor.P4;
}
}

=>enum declared within a class

class Processorvalue{
enum Processor{P4,DUALCORE,COREDUO};
Processor process;
}

public class Processtest{
public static void main(String a[]){
Processorvalue pval= new Processorvalue();
pval.process=Processorvalue.Processor.P4;
}
}

Note:-Access methods and syntax pattern depend on the way of implementation of enum.

How to use methods and variables within an enum -Part 3

Useful links:-
Home
All about enums:How to create ,How to use -- part 1
Why java classes are not marked "final"

0 comments:

About This Blog

This Blog is all about Java and programming.This blog is written by Vaibhav Pandey(Read More about him) .He is a Computer Science Graduate .You can contact the author at javatute@gmail.com for any suggestion or Query.You can also contact the author for advertising on this blog.All the material presented here is the property of author and its reproduction in any form is strictly prohibited.

Disclaimer:-Download links provided here are not of author in any means.These are found over the Internet.
Page copy protected against web site content infringement by Copyscape

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP