enum in java
Hello, if you some help with your work or student life then click this link. (If you want to convert your audio file to pdf or want us to narrate your word file, so that you can listen to rather than read it. it will done by a human.) https://linktr.ee/wisethero
Java The Complete Reference 11th Edition: https://amzn.to/3pCh9PZ
SignUp For Audible:https://www.amazon.in/dp/B077S5CVBQ/?ref=assoc_tag_sept19?actioncode=AINOTH066082819002X&tag=AssociateTrackingIDcodeonamics03-21
Signup Today:http: //www.fiverr.com/s2/cd10dfd1a0
Join Fiverr Business, (It will Help Our Channel Grow, Please):
https://track.fiverr.com/visit/?bta=210111&brand=fb
Learn something new today:
https://track.fiverr.com/visit/?bta=210111&brand=andco
Grow Your Business Today:
https://track.fiverr.com/visit/?bta=210111&brand=andco
Enumerations serve the purpose of representing a group of named constants in a programming language. For example the 4 suits in a deck of playing cards may be 4 enumerators named Club, Diamond, Heart, and Spade, belonging to an enumerated type named Suit. Other examples include natural enumerated types (like the planets, days of the week, colors, directions, etc.).
Enums are used when we know all possible values at compile time, such as choices on a menu, rounding modes, command line flags, etc. It is not necessary that the set of constants in an enum type stay fixed for all time.
In Java (from 1.5), enums are represented using enum data type. Java enums are more powerful than C/C++ enums . In Java, we can also add variables, methods and constructors to it. The main objective of enum is to define our own data types(Enumerated Data Types).
Declaration of enum in java :
Enum declaration can be done outside a Class or inside a Class but not inside a Method.
// A simple enum example where enum is declared
// outside any class (Note enum keyword instead of
// class keyword)
enum Color
{
RED, GREEN, BLUE;
}
public class Test
{
// Driver method
public static void main(String[] args)
{
Color c1 = Color.RED;
System.out.println(c1);
}
}
Output :
RED
// enum declaration inside a class.
public class Test
{
enum Color
{
RED, GREEN, BLUE;
}
// Driver method
public static void main(String[] args)
{
Color c1 = Color.RED;
System.out.println(c1);
}
}
Output :
RED
First line inside enum should be list of constants and then other things like methods, variables and constructor.
According to Java naming conventions, it is recommended that we name constant with all capital letters
Important points of enum :
Every enum internally implemented by using Class.
/* internally above enum Color is converted to
class Color
{
public static final Color RED = new Color();
public static final Color BLUE = new Color();
public static final Color GREEN = new Color();
}*/
Every enum constant represents an object of type enum.
enum type can be passed as an argument to switch statement.
// A Java program to demonstrate working on enum
// in switch case (Filename Test. Java)
import java.util.Scanner;
// An Enum class
enum Day
{
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY;
}
// Driver class that contains an object of "day" and
// main().
public class Test
{
Day day;
// Constructor
public Test(Day day)
{
this.day = day;
}
// Prints a line about Day using switch
public void dayIsLike()
{
switch (day)
{
case MONDAY:
System.out.println("Mondays are bad.");
break;
case FRIDAY:
System.out.println("Fridays are better.");
break;
case SATURDAY:
case SUNDAY:
System.out.println("Weekends are best.");
break;
default:
System.out.println("Midweek days are so-so.");
break;
}
}
// Driver method
public static void main(String[] args)
{
String str = "MONDAY";
Test t1 = new Test(Day.valueOf(str));
t1.dayIsLike();
}
}
Output:
Mondays are bad.
Every enum constant is always implicitly public static final. Since it is static, we can access it by using enum Name. Since it is final, we can’t create child enums.
We can declare main() method inside enum. Hence we can invoke enum directly from the Command Prompt.
// A Java program to demonstrate that we can have
// main() inside enum class.
enum Color
{
RED, GREEN, BLUE;
// Driver method
public static void main(String[] args)
{
Color c1 = Color.RED;
System.out.println(c1);
}
}
Output :
RED
Enum and Inheritance :
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «enum in java», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.