fbpx

How does Java handle multiple inheritance? Explain with an example.

Java doesn't support multiple inheritance through classes to avoid the diamond problem. However, it can be achieved through interfaces:

interface A {
    void methodA();
}

interface B {
    void methodB();
}

class MyClass implements A, B {
    public void methodA() {
        // implementation
    }
    
    public void methodB() {
        // implementation
    }
}

 

# Dream job to realty