Maruthi Krishna has Published 1025 Articles

Can we override default methods in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 12:42:05

An interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Since Java8 static methods and default methods are introduced in interfaces. Unlike other abstract methods these are the methods can have a default implementation. If you have default method in ... Read More

What is the use of default methods in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 12:06:38

An interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.It is a specification of method prototypes. Whenever you need to guide the programmer or, make a contract specifying how the methods and fields of a type should be you ... Read More

How to solve diamond problem using default methods in Java

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 11:53:31

Inheritance is a relation between two classes where one class inherits the properties of the other class. This relation can be defined using the extends keyword as −public class A extends B{}The class which inherits the properties is known as sub class or, child class and the class whose properties are ... Read More

How to convert a super class variable into a sub class type in Java

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 11:52:56

Inheritance is a relation between two classes where one class inherits the properties of the other class. This relation can be defined using the extends keyword as −public class A extends B{}The class which inherits the properties is known as sub class or, child class and the class whose properties are ... Read More

How to convert a sub class variable into a super class type in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 11:52:37

Inheritance is a relation between two classes where one class inherits the properties of the other class. This relation can be defined using the extends keyword as −public class A extends B{}The class which inherits the properties is known as sub class or, child class and the class whose properties are ... Read More

Explain the usage of the valueOf() method of the String class in Java

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 11:36:43

The String class of the java.lang package represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings are constant, their values cannot be changed after they are created.The valueOf() method of the String class accepts a char or, char array ... Read More

How to convert a double value into a Java String using append method?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 11:36:26

The append method of the StringBuilder or StringBuffer objects accept a boolean or, char or, char array or, double or, float or, int or, long or, String value as parameter and adds it to the current object.You can append the required double value to the method and retrieve a String from obtained StringBuffer ... Read More

Can we define an enum inside a method in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 11:35:52

Enumerations in Java represents a group of named constants, you can create an enumeration using the following syntax −enum Days {    SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }We can an enumeration inside a class. But, we cannot define an enum inside a method. If you try to do ... Read More

Can we define an enum inside a class in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 11:34:06

Enumerations in Java represents a group of named constants, you can create an enumeration using the following syntaxenum Days {    SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }Yes, we can define an enumeration inside a class. You can retrieve the values in an enumeration using the values() method.ExampleLive Demopublic class ... Read More

How to convert a double value into a Java String using format method?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 11:31:05

This method accepts a format String and arguments (varargs) and returns a String object of the given variable(s) in the specified format.You can format a double value into a String using the format() method. To it pass “%f” as the format string (along with the required double value).ExampleLive Demoimport java.util.Scanner; ... Read More

Advertisements