Skip to content
C

Java Interview Questions

Interfaces Interview Questions

Interface contracts, multiple implementation, interface inheritance, and functional/marker interfaces.

Question 1: What is an interface in Java?

Ans

An interface defines a contract of method signatures, and since Java 8, default and static methods too, that any implementing class agrees to fulfill, without necessarily providing the implementation itself. It describes what a class can do, not how it does it.

Example

java
interface Payment { void pay(double amount); } class CardPayment implements Payment { public void pay(double amount) { System.out.println("Paid " + amount + " by card"); } }

Important Point

All fields declared in an interface are implicitly public, static, and final, whether or not you write those keywords.

Question 2: What is a marker interface, and how does it differ from a normal interface?

Ans

A marker interface has no methods at all — implementing it simply tags a class with a property or capability that other code or frameworks can check for using instanceof, rather than requiring the class to implement any specific behavior. Serializable and Cloneable are classic historical examples.

Example

java
class Report implements Serializable { } // no methods to implement, just a tag

Important Point

Modern Java code often prefers annotations over marker interfaces for tagging classes, but marker interfaces are still useful when the tag needs to participate in the type system, for example in method overloading or generic bounds.

Continue Your Preparation