Venkata Sai has Published 62 Articles

What are enumerations in Java? How to retrieve values from an enum?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

504 Views

Enumeration (enum) in Java is a datatype which stores a set of constant values. You can use enumerations to store fixed values such as days in a week, months in a year etc.You can define an enumeration using the keyword enum followed by the name of the enumeration as −enum ... Read More

Can we have variables and methods in an enum in Java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

3K+ Views

Enumeration (enum) in Java is a datatype which stores a set of constant values. You can use enumerations to store fixed values such as days in a week, months in a year etc.You can define an enumeration using the keyword enum followed by the name of the enumeration as −enum ... Read More

Can we create an enum with custom values in java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

7K+ Views

Enumeration (enum) in Java is a datatype which stores a set of constant values (Strings in general). You can use enumerations to store fixed values such as days in a week, months in a year etc.enum Days { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }Custom values ... Read More

How to use an enum with switch case in Java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

1K+ Views

Enumeration (enum) in Java is a datatype which stores a set of constant values. You can use enumerations to store fixed values such as days in a week, months in a year etc.enum Days { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }You can also define an enumeration with custom ... Read More

How to iterate the values in an enum in Java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

14K+ Views

Enumeration (enum) in Java is a datatype which stores a set of constant values. You can use enumerations to store fixed values such as days in a week, months in a year etc.enum Days { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }You can iterate the contents ... Read More

How to convert a String to an enum in Java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

3K+ Views

The valueOf() method of the Enum class in java accepts a String value and returns an enum constant of the specified type.ExampleLet us create an enum with name Vehicles with 5 constants representing models of 5 different scoters with their prices as values, as shown below −enum Vehicles { ... Read More

Explain about field hiding in java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

859 Views

Whenever you inherit a superclass a copy of superclass’s members is created at the subclass and you using its object you can access the superclass members.If the superclass and the subclass have instance variable of same name, if you access it using the subclass object, the subclass field hides the ... Read More

What is variable shadowing in java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

4K+ Views

In Java you can declare three types of variables namely, instance variables, static variables and, local variables.Local variables − Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has ... Read More

What are the rules to be followed while using varargs in java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

212 Views

Since JSE1.5 you can pass a variable number of values as argument to a method. These arguments are known as var args and they are represented by three dots (…)Syntaxpublic myMethod(int ... a) { // method body }Rules to follow while using varargs in JavaWe can have ... Read More

What happens when you add a double value to a String in java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

2K+ Views

The “+” operator with a String acts as a concatenation operator.Whenever you add a String value to a double using the “+” operator, both values are concatenated resulting a String object.In-fact adding a double value to String is the easiest way to convert a double value to Strings.Exampleimport java.util.Scanner;   ... Read More

Advertisements