retagged by
10,667 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$
retagged by

1 Answer

1 votes
1 votes

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