Venkata Sai has Published 72 Answers

Does Java support multiple inheritance? Why? How can we resolve this?

Venkata Sai

Venkata Sai

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

Whenever, you extend a class a copy of superclass’s members is available to the subclass object and, when you can call the method of the superclass using the object of the subclass.ExampleIn the following example, we have a class named SuperClass with a method with name demo(). We are extending ... Read More

Can we cast an object reference to an interface reference in java? If so when?

Venkata Sai

Venkata Sai

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

Yes, you can.If you implement an interface and provide body to its methods from a class. You can hold object of the that class using the reference variable of the interface i.e. cast an object reference to an interface reference.But, using this you can access the methods of the interface ... Read More

Explain restrictions on using enum in java?

Venkata Sai

Venkata Sai

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

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

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

Venkata Sai

Venkata Sai

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

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

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

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

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

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

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

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

Advertisements