Core Java Interview Questions-interfaces

This Core Java Interview Questions-Interfaces page provides all the interview questions on java interfaces including what is the interface, how to implement the interface, instantiation of the interface, access static members and non-static members of interface and much more with suitable answers.

What is an interface ?
The complete declaration(prototype) of an object.

What type of methods allowed inside interface?
Only non-static abstract methods and static methods.

Can we define constructor inside interface?
Not allowed.

Can we instantiate an interface?
No, Without constructor, we cannot instantiate an interface.

Can we define main() inside interface?
Since jdk1.8, it is allowed to define static methods inside interface. Hence the main() method is allowed as
it was static.

Do we need to specify interface methods as abstract?
No, interface methods are by default public and abstract.

Can we place instance variables inside interface?
Instance variables belong to object and interface object creation is not possible.

Can we place static variables inside interface?
interface variables are public and static by default.

Why a class “implements” interface instead of “extends”?
In case of a class or abstract class, we can extend(update) pre-defined functionality.
In case of the interface, we need to “implements” every specification.

How to achieve multiple-inheritance using interfaces?
One interface can extend more than one interface in java.
Hence we can implement Multiple Inheritance.

Why do we need to maintain interface in application after its implementation?
After implementation of the interface, we can refer the implemented class object using interface name
only. Hence we need to maintain.

Can a class implement more than one interface?
Yes, one class can implement many interfaces in java application.

Can we implement an interface without overriding all the specifications of interface?
Yes, but the implemented class become an abstract class.

>Core Java Interview Questions-Packages<

Share this