Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the primary advantage of using interfaces over abstract classes in Java?

  • A.Interfaces can have constructors
  • B.A class can implement multiple interfaces
  • C.Interfaces can have instance variables
  • D.Interfaces provide faster execution

Answer: B

The main advantage is that a class can implement multiple interfaces.

Java allows a class to extend only one class, abstract or not, but to implement any number of interfaces. Interfaces are therefore Java's way of giving a class several types, a form of multiple inheritance of type.

The other options are false. Interfaces cannot have constructors, and they cannot have instance variables, since all their fields are implicitly public, static and final. They give no speed advantage. Abstract classes are the ones that can have constructors and instance state.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.