Tech Sawy
Tech Sawy

Reputation: 91

Is it overloading if a class implements muplitple interfaces with similar methods?

I'm curious to know whether it could be considered as method overloading if a class implements two or more interfaces with similar methods. If not then what's the right terminology?

Take an example

public interface I1 {
  int method1(String input);
}

public interface I2 {
  void method1(int input);
}

public class C1 implements I1, I2 {
  public int method1(String input){ return 0;}

  public void method1(int input){}
}

Upvotes: 0

Views: 55

Answers (1)

GhostCat
GhostCat

Reputation: 140525

Overloading boils down to:

In Java, two or more methods may have the same name if they differ in parameters (different number of parameters, different types of parameters, or both). These methods are called overloaded methods and this feature is called method overloading.

From here.

So, obviously, your class C1 does overload method1(). The fact that it does that in order to override the two methods doesn't change that. It doesn't matter to the definition of overloading if overriding happens, too.

Upvotes: 6

Related Questions