Java Interface Interview MCQ Questions and Answers

Study and learn Interview MCQ Questions and Answers on Java Interface. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save as PDF option next using any Web Browser.

Go through Java Theory Notes on Interface and Java 8 Default and Static Methods in Interfaces before reading these objective questions.



1) An interface in Java is like a 100% ____.
A) abstract class
B) public class
C) inner class
D) anonymous class
Answer [=]
A
Explanation:

Yes. If 100% of methods in an abstract class are marked abstract, then it is comparable to an interface in Java.

2) A Java Interface is not considered a class. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
A
Explanation:

True. A class and an Interface have different inheritance rules.

3) Choose the correct syntax below for defining an Interface in Java.
A)
interface NAME
{
  //abstract methods
}
B)
abstract interface NAME
{
  //abstract methods
}
C)
public interface NAME
{
  //abstract methods
}
D) All the above
Answer [=]
D
Explanation:

There is no need to explicitly mention ABSTRACT keyword to define an interface.

4) Choose a correct statement about Java Interfaces?
A) Interface contains only abstract methods by default.
B) A Java class can implement multiple interfaces
C) An Interface can extend or inherit another Interface.
D) All the above
Answer [=]
D
5) A Java Class inherits Constants and Methods of an Interface using ____ keyword.
A) INTERFACE
B) IMPLEMENTS
C) EXTENDS
D) All the above
Answer [=]
B
Explanation:

IMPLEMENTS keyword

6) What is the output of the below Java program with an Interface?
interface Bus
{
  void move();
}
class ElectricBus implements Bus
{
  public void move()
  {
    System.out.println("Implemented  move() method.");
  }	
}
public class InterfaceTest1
{
  public static void main(String[] args)
  {
    new ElectricBus().move();
  }
}
A) No output
B) Implemented move() method.
C) Compiler error
D) None of the above
Answer [=]
B
7) What is the output of the below Java program with an Interface?
interface Car
{
  int basePrice=1000;
}
public class InterfaceTest2 implements Car
{
  void changePrice()
  {
    basePrice = 2000;
    System.out.print(basePrice);
  }
  public static void main(String[] args)
  {
    new InterfaceTest2().changePrice();
  }
}
A) 1000
B) 2000
C) Compiler error
D) None of the above
Answer [=]
C
Explanation:

Java Interface treats its variables like constants. So, the classes implementing Interfaces, can not reassign values to the variables.



8) What is the output of the below Java program with an Interface?
interface Book
{
  char type='C';	
}
public class InterfaceTest3
{
  public static void main(String[] args)
  {
    System.out.println(new Book().type);
  }
}
A) C
B) No output
C) Compiler error
D) None of the above
Answer [=]
C
Explanation:

You can not instantiate an Interface in Java. So, using the keyword "new" does not create new objects of an Interface.

9) All Interface variables are ___ by default in Java.
A) public
B) final
C) public and final
D) None
Answer [=]
C
Explanation:

Yes, public and final. In other words, these are constants.

10) All Interface methods in Java are ____ by default.
A) public
B) abstract
C) public and abstract
D) None of the above
Answer [=]
C
Explanation:

Interface automatically marks all its methods as public and abstract. So, you need not add these keywords again while writing the program.

11) A Class implementing an Interface can use ____ access modifier before the implemented methods.
A) private
B) protected
C) public
D) All the above
Answer [=]
C
Explanation:

Only a "public" access modifier is allowed.

12) A Java Class implementing an Interface can define a variable with the same name as that of the Interface constant. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
A
Explanation:

True.

13) What is the output of the below Java program with an Interface?
interface Worm
{
  int teeth=2;
}
class BookWorm implements Worm
{
  int teeth=4;
  void show()
  {
    teeth= 5;
    System.out.println("Teeth: " + teeth);
  }
}
public class InterfaceTest4
{
  public static void main(String[] args)
  {
    new BookWorm().show();
  }
}
A) Teeth: 4
B) Teeth: 5
C) Compiler error as teeth is a constant in Worm interface.
D) None of the above
Answer [=]
B
Explanation:

You can reassign an interface's constant. You can define a variable with the same name in the implementing class.

14) A Java Interface can not declare constructors. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
A
Explanation:

True. You can define a constructor inside an Interface.



15) What is the output of the below Java program with an Interface?
interface Floor
{
  Floor(){ }
}
public class InterfaceTest5
{
  public static void main(String[] args)
  {
    System.out.print("Floor");
  }
}
A) Floor
B) No output
C) Compiler error
D) None
Answer [=]
C
Explanation:

Interfaces can not have constructors.

16) Java 8 (Java 1.8) introduced the ___ feature.
A) Default methods
B) Static methods
C) Default and Static methods
D) None of the above
Answer [=]
C
Explanation:

Yes, static and default methods. Remember that "default" is a keyword.

17) Java Interface static methods have ___ compatibility with the existing project code.
A) Forward
B) Backward
C) Both Forward and Backward
D) -
Answer [=]
C
Explanation:

Forward compatibility means, the implementing classes may be modified to access these static methods. It is optional. It does not throw exceptions. The existing classes still do not utilize these new static methods of the interface. So, it is backward compatible too.

18) Java Interface DEFAULT methods have ___ compatibility with the existing project code.
A) Forward
B) Backward
C) Backward and Forward
D) -
Answer [=]
C
Explanation:

Backward and Forward Compatibility. It means, the existing project-code compiles as it is without asking for overriding the newly added Default method inside the Interface. Without the keyword DEFAULT, the project build fails. All the new Classes start implementing these default methods. It is forward compatibility.

19) The DEFAULT methods of an Interface are suitable mostly for ___ type of projects.
A) Open Source (Public Repositories)
B) Closed Source (Private Repositories)
C) -
D) -
Answer [=]
A
Explanation:

Open Source projects do not know how many organizations or users have been dependent on the project. So, it is advised to take advantage of the DEFAULT methods of an Interface to introduce new features.

20) Is it possible to remove the keyword DEFAULT and make the method abstract again in an Interface, if the Interface belongs to a Closed-Source project?
A) Yes
B) No
C) -
D) -
Answer [=]
A
Explanation:

Yes. Closed source projects can still introduce new features using the same keyword DEFAULT. Once they complete the implementation of all the DEFAULT methods in the implementing classes, they can completely remove default methods and provide only abstract methods. The end-user of a Closed-Source project is the company itself that developed it.

21) The annotation used in Java to override the method of a super-class or interface by the subclass or implementing class is ___.
A) @override
B) @Override
C) @super
D) @subclass
Answer [=]
B
Explanation:

@Override



22) It is ___ to override the static method of an Interface in Java.
A) possible
B) not possible
C) -
D) -
Answer [=]
B
Explanation:

Not possible to override the static method. The compiler shows an error.

23) A Java static method can not be ___.
A) private or protected
B) final
C) abstract
D) All the above
Answer [=]
D
Explanation:

You can not use the keywords, private, protected, final and abstract, before a static method of an Interface.

24) Which is the missing java code in the class implementing an Interface below?
interface Linein
{  void addInput();	}

interface Lineout
{  void addOutput(); }

class Speaker implements Linein, Lineout
{
  //MISSING CODE
}

A)
class Speaker implements Linein, Lineout
{
  @Override
  public void addOutput() { }

  @Override
  public void addInput() {  }	
}
B)
class Speaker implements Linein, Lineout
{
  @Override
  public void addOutput() { }
}
C)
class Speaker implements Linein, Lineout
{
  @Override
  public void addInput() {  }	
}
D) All the above
Answer [=]
A
Explanation:

As the Speaker class is implementing two interfaces Linein and Lineout, the abstract methods of all the interfaces have to be implemented by the first concrete class.

25) Which is the missing code to successfully compile the below Java program with abstract classes and Interfaces?
interface A
{  void a(); }

abstract class B implements A
{  abstract void b(); }

class C extends B
{
  //Missing methods
}
A)
@Override
public void a() {  }

@Override
void b() {}
B)
@Override
public void a() {  }
C)
@Override
void b() {}
D) All the above
Answer [=]
A
Explanation:

The first concrete class should implement all the abstract methods of superclasses and interfaces.

26) A Superinterface is comparable to a Superclass. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
A
Explanation:

True.

27) A Static method of an Interface should be accessed with _____ and a DOT operator.
A) Class Name
B) Interface Name
C) An object of a concrete class
D) None of the above
Answer [=]
B
Explanation:

You should not use object references to access the static method of an Interface. Just use Interface name and DOT (.) operator directly.



 

 

Show some care. Like or Subscribe.

C MCQ App by ExamTray (Give us 5*)

EXAMTRAY C MCQ android app link

Java MCQ App by ExamTray (Give us 5*)

EXAMTRAY Java MCQ android app link
ALL MCQ App by ExamTray (Give us 5*) EXAMTRAY android app link
WUnsaved Whatsapp msg to Unknown(Give us 5*) WUnsaved android app link
Virtual Tape GPS (Give us 5*) Virtual Tape GPS android app link