All about enums:How to create ,How to use -- part 1
enum is a special kind of class in which we can list enumaerated constant values.We can add constants,methods and instance variables and a brand new stranger called constant specific class body.
enums lets you choose a variable to having one of a few pre-defined set of values.That is selecting one value from an enumerated list.
Simple declaration for an enum is as follows:-
enum Processor{P4,DUALCORE,COREDUO }
to fetch a value from an enum you must use following syntax:-
Processor process=Processor.P4;
Note:-You can put semicolon at the end of curly braces in declaration because they are optional.So whenever you see an enum declaration ending with semicolon never get confused.Remember semicolon is optional.
Rules regarding enums:-
There are some rules while using enums
Rule 1:-enums can be declared as their own seperate class.
Rule 2:-enums can also be a class member.
Rule 3:-enums must not be declared within a method.
Rule 4:-enums can have only to access modifiers
1.defult(which is by default no need to specify)
2.public
There are two ways of using enums
1.As own class.
2.Within a class.
To view examples Proceed to part 2
Suggested Links:-
Home
Why public class not marked "final"
Variables
enums lets you choose a variable to having one of a few pre-defined set of values.That is selecting one value from an enumerated list.
Simple declaration for an enum is as follows:-
enum Processor{P4,DUALCORE,COREDUO }
to fetch a value from an enum you must use following syntax:-
Processor process=Processor.P4;
Note:-You can put semicolon at the end of curly braces in declaration because they are optional.So whenever you see an enum declaration ending with semicolon never get confused.Remember semicolon is optional.
Rules regarding enums:-
There are some rules while using enums
Rule 1:-enums can be declared as their own seperate class.
Rule 2:-enums can also be a class member.
Rule 3:-enums must not be declared within a method.
Rule 4:-enums can have only to access modifiers
1.defult(which is by default no need to specify)
2.public
There are two ways of using enums
1.As own class.
2.Within a class.
To view examples Proceed to part 2
Suggested Links:-
Home
Why public class not marked "final"
Variables


















0 comments:
Post a Comment
Post a Comment