1

A common "question to which the answer is no" is does Java support multiple inheritance?

I'm looking for some elaboration on how this rule is handled by the (Oracle) JVM; more specifically:

At runtime does the JVM have any notion of an Interface or does it just treat it like an abstract class that happens to not implement any methods?

In other words, would my code become this?

My Code:

public class A extends B implements C {

public interface C {

Compiles into:

public class A extends B, C {

public abstract class C {

In which case, the JVM could be said to support multiple inheritance so long no more than one parent class implements methods.

Or are interfaces more deeply woven into the guts of the JVM?

1
  • 2
    Note that more than one of the implemented interfaces can include the same method. Commented Jul 30, 2013 at 12:51

1 Answer 1

2

At runtime, the JVM does have a notion of interfaces. Methods called through an interface type are invoked with invokeinterface.

Compiling interfaces into abstract classes would not work:

  • A single method may indeed be implemented by more than one of the interfaces that a class implements.
  • An interface method may be invoked on more than one type that implements the interface.
  • An interface provides no implementation for its methods.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.