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"
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:
Post a Comment
Post a Comment