Thursday, 11 April 2024

Code demonstrating multiple inheritence in JAVA VIA INTERFACE

 interface A {

    void methodA();

}


interface B {

    void methodB();

}


// Class C implements both interfaces A and B

class C implements A, B {

    public void methodA() {

        System.out.println("Method A implementation");

    }


    public void methodB() {

        System.out.println("Method B implementation");

    }

}


public class Main {

    public static void main(String[] args) {

        C obj = new C();

        obj.methodA(); // Output: Method A implementation

        obj.methodB(); // Output: Method B implementation

    }

}


No comments:

Post a Comment

Good thoughtful question on Binary search on answers

Problem link:  https://leetcode.com/problems/maximize-score-of-numbers-in-ranges/description/ Solution: //import java.util.Arrays; class So...