Maruthi Krishna has Published 951 Articles

Can we create an object for an interface in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 14:14:48

15K+ Views

No, you cannot instantiate an interface. Generally, it contains abstract methods (except default and static methods introduced in Java8), which are incomplete.Still if you try to instantiate an interface, a compile time error will be generated saying “MyInterface is abstract; cannot be instantiated”.In the following example we an interface with ... Read More

What are defender methods or virtual methods in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 14:10:49

498 Views

The default methods in an interface in Java are also known as defender methods or, virtual methods.The defender/virtual methods are those that will have a default implementation in an interface. You can define defender/virtual methods using the default keyword as −default void display() {    System.out.println("This is a default method"); ... Read More

Can interfaces have Static methods in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 14:09:24

7K+ Views

An interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.A static method is declared using the static keyword and it will be loaded into the memory along with the class. You can access static methods using class name without ... Read More

Can we create non static variables in an interface using java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 14:08:40

2K+ Views

Interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Since all the methods are abstract you cannot instantiate it. To use it, you need to implement this interface using a class and provide body to all the abstract methods int ... Read More

Can we declare an abstract method, private, protected, public or default in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 13:45:25

10K+ 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.Declaring an abstract method ... Read More

What happens if we define a concrete method in an interface in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 13:44:28

2K+ Views

Interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Since all the methods are abstract you cannot instantiate it. To use it, you need to implement this interface using a class and provide body to all the abstract methods int ... Read More

Is it possible to catch multiple Java exceptions in single catch block?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 13:39:07

953 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.Multiple exceptions in a codeBefore Java 7 whenever we have a code that may ... Read More

Can we define an abstract class without abstract method in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 13:37:31

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

Can we create an object for the abstract class in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 13:36:39

1K+ 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.A class which contains ... Read More

Can we declare an abstract method final or static in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 13:36:04

10K+ 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.Declaring abstract method staticIf ... Read More

Advertisements