filmov
tv
Learn Java Tutorial for Beginners, Part 48: Enum

Показать описание
In this video by Quordnet Academy for the series Learn Java Tutorial for Beginners how to use Enum have been discussed.
If you would like to discover even more about java programming tutorial or the java complete course I advise you to check out the playlist :
Java Enums
Enums
An enum is a special "class" that represents a group of constants (unchangeable variables, like final variables).
To create an enum, use the enum keyword (instead of class or interface), and separate the constants with a comma. Note that they should be in uppercase letters:
Example
enum Level {
LOW,
MEDIUM,
HIGH
}
You can access enum constants with the dot syntax:
Level myVar = Level.MEDIUM;
Enum is short for "enumerations", which means "specifically listed".
Enum inside a Class
You can also have an enum inside a class:
Example
public class MyClass {
enum Level {
LOW,
MEDIUM,
HIGH
}
public static void main(String[] args) {
Level myVar = Level.MEDIUM;
}
}
The output will be:
MEDIUM
Enum in a Switch Statement
Enums are often used in switch statements to check for corresponding values:
Example
enum Level {
LOW,
MEDIUM,
HIGH
}
public class MyClass {
public static void main(String[] args) {
Level myVar = Level.MEDIUM;
switch(myVar) {
case LOW:
break;
case MEDIUM:
break;
case HIGH:
break;
}
}
}
The output will be:
Medium level
Loop Through an Enum
The enum type has a values() method, which returns an array of all enum constants. This method is useful when you want to loop through the constants of an enum:
Example
}
The output will be:
LOW
MEDIUM
HIGH
Difference between Enums and Classes
An enum can, just like a class, have attributes and methods. The only difference is that enum constants are public, static and final (unchangeable - cannot be overridden).
An enum cannot be used to create objects, and it cannot extend other classes (but it can implement interfaces).
Why And When To Use Enums?
Use enums when you have values that you know aren't going to change, like month days, days, colors, deck of cards, etc.
Possibly if you have doubt comment below and let me understand what else I can help you with information in java.This playlist is a full fledged java programming for beginners and java tutorial for beginners which is given above.
Please share with your friends the video to assist other people looking for java programming tutorial or object oriented programming java .
To never miss an update from or channel hit the subscribe button first and if already subscribe hit the bell icon.
1.Follow us on INSTAGRAM for Interesting posts
2.Follow us on LINKEDIN for interesting content on different aspects
3.Don't forget to like our FACEBOOK to get the most out of it
4.Follow us on twitter to get a mix of all
5.If you want to get us on TUMBLR please then click on the link given below
6.Do join our OFFICIAL Telegram for notes of different things
7.For get job update regularly both private and government do join this telegram channel
#quordnetacademy, #java_tutorial_series, #javatutorialseries
If you would like to discover even more about java programming tutorial or the java complete course I advise you to check out the playlist :
Java Enums
Enums
An enum is a special "class" that represents a group of constants (unchangeable variables, like final variables).
To create an enum, use the enum keyword (instead of class or interface), and separate the constants with a comma. Note that they should be in uppercase letters:
Example
enum Level {
LOW,
MEDIUM,
HIGH
}
You can access enum constants with the dot syntax:
Level myVar = Level.MEDIUM;
Enum is short for "enumerations", which means "specifically listed".
Enum inside a Class
You can also have an enum inside a class:
Example
public class MyClass {
enum Level {
LOW,
MEDIUM,
HIGH
}
public static void main(String[] args) {
Level myVar = Level.MEDIUM;
}
}
The output will be:
MEDIUM
Enum in a Switch Statement
Enums are often used in switch statements to check for corresponding values:
Example
enum Level {
LOW,
MEDIUM,
HIGH
}
public class MyClass {
public static void main(String[] args) {
Level myVar = Level.MEDIUM;
switch(myVar) {
case LOW:
break;
case MEDIUM:
break;
case HIGH:
break;
}
}
}
The output will be:
Medium level
Loop Through an Enum
The enum type has a values() method, which returns an array of all enum constants. This method is useful when you want to loop through the constants of an enum:
Example
}
The output will be:
LOW
MEDIUM
HIGH
Difference between Enums and Classes
An enum can, just like a class, have attributes and methods. The only difference is that enum constants are public, static and final (unchangeable - cannot be overridden).
An enum cannot be used to create objects, and it cannot extend other classes (but it can implement interfaces).
Why And When To Use Enums?
Use enums when you have values that you know aren't going to change, like month days, days, colors, deck of cards, etc.
Possibly if you have doubt comment below and let me understand what else I can help you with information in java.This playlist is a full fledged java programming for beginners and java tutorial for beginners which is given above.
Please share with your friends the video to assist other people looking for java programming tutorial or object oriented programming java .
To never miss an update from or channel hit the subscribe button first and if already subscribe hit the bell icon.
1.Follow us on INSTAGRAM for Interesting posts
2.Follow us on LINKEDIN for interesting content on different aspects
3.Don't forget to like our FACEBOOK to get the most out of it
4.Follow us on twitter to get a mix of all
5.If you want to get us on TUMBLR please then click on the link given below
6.Do join our OFFICIAL Telegram for notes of different things
7.For get job update regularly both private and government do join this telegram channel
#quordnetacademy, #java_tutorial_series, #javatutorialseries