0
interface A {
    public void eg1();
}

interface B {
    public void eg1();
}

public class SomeOtherClassName implements A, B {
    @Override
    public void eg1() {
        System.out.println("test.eg1()");
    }

}

What is the output and what occurs if method is overriden in interface?

Rahul
  • 128
  • 1
  • 14

1 Answers1

0
  • First of all it's of no use to implement both class A and B as both of them has same method signature i.e both has same method name and return type.
  • Secondly you'll need a main method to run the program.
  • Also in interface you can only declare the methods, the implementation has to be done in the class which implements it.

     interface A {
        public void eg1();
    }
    
    interface B {
        public void eg1();
    }
    
    public class Test implements A{
        @Override
        public void eg1() {
            System.out.println("test.eg1()");
        }
        public static void main (String args[]) {
            A a = new test();
            a.eg1();
        }
    }
    

Output : test.eg1()

Rahul
  • 128
  • 1
  • 14
  • refer this for further understanding http://stackoverflow.com/questions/18944539/abstract-class-real-time-example – Rahul May 15 '17 at 08:13