Maruthi Krishna has Published 951 Articles

What is blank final variable? What are Static blank final variables in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:19:27

2K+ Views

Static variables − Static variables are also known as class variables. You can declare a variable static using the keyword. Once you declare a variable static there would only be one copy of it in the class, regardless of how many objects are created from it.public static int num = ... Read More

Constructor overloading in enumerations in Java.

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:17:19

712 Views

Overloading is a one of the mechanisms to achieve polymorphism where, a class contains two methods with same name and different parameters.Whenever you call this method the method body will be bound with the method call based on the parameters.Constructor overloadingSimilar to methods you can also overload constructors i.e. you ... Read More

How to call another enum value in an enum's constructor using java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:16:29

2K+ 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

How can an exception be thrown manually by a programmer in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:11:35

5K+ Views

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.Exampleimport java.util.Scanner; public class ExceptionExample {    public static void main(String args[]) {   ... Read More

Is it possible to have multiple try blocks with only one catch block in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:10:01

8K+ Views

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.Exampleimport java.util.Scanner; public class ExceptionExample {    public static void main(String args[]) {   ... Read More

How to read DataInputStream until the end without need to catch an EOFException in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:09:12

975 Views

While reading the contents of a file in certain scenarios the end of the file will be reached in such scenarios a EOFException is thrown.Especially, this exception is thrown while reading data using the Input stream objects. In other scenarios a specific value will be thrown when the end of ... Read More

Does static factory method internally use new keyword to create object in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:00:04

112 Views

Factory pattern is a design pattern (creational pattern) which is used to create multiple objects based on the data we provide. In it we create an object abstracting the process of creation.ExampleBelow given is the example implementation of the factory pattern. Here, we have an interface with name Employee and ... Read More

How static class Object is created without reference of outer class in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:59:06

1K+ Views

A static member (method/variable) belongs to the class and it will be loaded into the memory along with the class. You can invoke it without creating an object. (using the class name as reference). There is only one copy of the static field available throughout the class i.e. the value ... Read More

Why static methods of parent class gets hidden in child class in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:57:37

2K+ Views

When we have two classes where, one extends another and if, these two classes have same method including parameters and return type (say, sample) the method in the sub class overrides the method in the super class.i.e. Since it is inheritance. If we instantiate the subclass a copy of superclass’s ... Read More

How to call a non-static method of an abstract class from a static method in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:56:05

8K+ Views

A method which does not have body is known as abstract method. It contains only method signature with a semi colon and, an abstract keyword before it.public abstract myMethod();To use an abstract method, you need to inherit it by extending its class and provide implementation to it.Abstract classA class which ... Read More

Advertisements