in Java retagged by
4,660 views
2 votes
2 votes

Which of the following is true about interfaces in Java? 

  1.  An interface can contain following type of members. $\dots$ public, static, final fields(i.e., constants)$\dots$default and static methods with bodies.
  2. An instance of interface can be created.
  3.  A class can implement multiple interfaces.
  4. Many classes can implement the same interface.
  1. $1,3$ and $4$
  2. $1,2$ and $4$
  3. $2,3$ and $4$
  4. $1,2,3$ and $4$
in Java retagged by
4.7k views

1 Answer

1 vote
1 vote

1. "An interface can contain following type of members. ...public,static,final fields(i.e., constants) ...default and static methods with bodies "

New features added in interfaces in JDK 9
From Java 9 onwards, interfaces can contain following also

  1. Static methods
  2. Private methods
  3. Private Static methods

Other things mentioned in question were previously also allowed. So 1 is true.

2. "An instance of interface can be created.:

We can’t create instance(interface can’t be instantiated) of interface but we can make reference of it that refers to the Object of its implementing class. (See reference for example).

So its false.

3. "A class can implement multiple interfaces "

True. Multiple inheritance is allowed through interface in Java, but not allowed through class.

4. "many classes can implement the same interface."

True.

So A is correct.

Ref:

https://www.geeksforgeeks.org/interfaces-in-ja va/

Answer:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true