Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Solve Diamond Interface Inheritance Problem in JAVA?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 12
    Answer it

    Hello. I'm trying to solve the following problem.

    I have 4 interfaces that are in a diamond shape and 2 classes.

    The requirements is to make the method calls work, while keeping f1 as the interface of x.

    Can you guys give me a hand?

     

    package lab4;

    public class Prob6 {

        public static void main(String[] args) {
            f1 x = new object();
            x.method1();
            x.method2();
            x.method3();
            x.method4();
        }

    }

    interface f1{
        void method1();
    }

    interface f2 extends f1{
        void method2();
    }

    interface f3 extends f1{
        void method3();
    }

    interface f4 extends f2,f3{
        void method4();
    }

    class object implements f4{
        
        public void method1() 
        {
            System.out.println("method 1");
        }
        public void method2() 
        {
            System.out.println("method 2");
        }
        public void method3() 
        {
            System.out.println("method 3");
        }
        public void method4() 
        {
            System.out.println("method 4");
        }
    }

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: