-1

Consider following scenario: I have two interfaces A and B. Both interfaces have a member function display().

public interface A {
   public function display() {
   }
}

public interface B {
   public function display() {
   }
}

class C implement A, B {
   public function display{
       //definition here
   }
}

I just want to know

  1. how many display() functions are available in class C?
  2. If there is one member function, how it is possible?
khelwood
  • 55,782
  • 14
  • 81
  • 108

2 Answers2

3

A brilliant explanation is at: Implementing two interfaces in a class with same method. Which interface method is overridden?

If a type implements two interfaces, and each interface define a method that has identical signature, then in effect there is only one method, and they are not distinguishable. If, say, the two methods have conflicting return types, then it will be a compilation error. This is the general rule of inheritance, method overriding, hiding, and declarations, and applies also to possible conflicts not only between 2 inherited interface methods, but also an interface and a super class method, or even just conflicts due to type erasure of generics.

Community
  • 1
  • 1
Sandeep Kaul
  • 2,957
  • 2
  • 20
  • 36
1

how many display() functions are available in class C?

Just only one

If there is one member function, how it is possible?

Because they have the same signature

But this is forbidden in java, it is not possible with the same name and different types, you can learn more about that here Java - Method name collision in interface implementation

Community
  • 1
  • 1
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140