MCQ Java Interfaces


Q) Which is correct option about java interface?

  1. Interface is used to achieve multiple inheritance in java
  2. Object of an interface cannot be created.
  3. An interface can extend another interface.
  4. All of the above

Answer: 4
Object of an interface cannot be created. Java does not support multiple inheritance using classes, but, you can achieve multiple inheritance using interfaces in java. Read how to achieve multiple inheritance in java using interfaces. A interface can also extends another interface or multiple interfaces in java programming.


Q) False statement about Java interface

  1. It is used to achieve abstraction and multiple inheritance in Java.
  2. It can be instantiated, means, we can create an object of an interface.
  3. There can be only abstract methods in the interface not method body.
  4. All are correct.

Answer: 2
We cannot create an object of an interface.


Q) What is output of the below java program?

interface IShape {
	void f();
}

class Circle implements IShape {
	
	public void f() {	
		System.out.println("Interface");
	}
	public void c() {
		System.out.println("class");
	}
}

public class Main {

	public static void main(String[] args) {
		
		IShape obj = new Circle();
		obj.f();	
	}
}

  1. Interface
  2. Class
  3. Compiler error

Answer: 1
NOTE: Many programmer get confused at this statement IShape obj = new Circle();. They think that object of an interface cannot be created. They are right. But at this statement, object of the Circle is created and not of the interface. IShape object is just a reference. So, program is correct.


Q) Java interface is used to

  1. Implement behaviour of multiple inheritance
  2. Achieve abstraction
  3. achieve loos coupling
  4. All of the above

Answer: 4


Q) Which of the following is true about interfaces in java?
Consider an interface that has 5 methods in it.

  1. A class can implement few methods which is required for the class.
  2. The class must implement all the five methods.

Answer: 2
Explanation: If a class is implementing an interface, then the class must implement all the abstract methods declared in the interface.


MCQ Java Interfaces

Scroll to top