[Solved] same method name but different class name [closed]


What is this concept called in JAVA?

This is not a concept , you have named the method same in two un-related classes . If one of the class was sub class of another then depending on the method signature , it would have been overriding or overloading.

You would have implemented run time polymorphism , if one of the class was a subclass of another :

 class abc {
  void show() {
    System.out.println("First Class");
  }
}

// def extends from abc
class def extends abc {
  // show() method was overridden here
  void show() {
    System.out.println("Second Class");
  }
}

class demo {
  public static void main(String args[]) {
    // Use the reference type abc, object of type abc
    abc a1 = new abc();
    // Use the reference type abc, object of type def
    abc a2 = new def();
    // invokes the show() method of abc as the object is of abc
    a1.show();
    // invokes the show() method of def as the object is of def
    a2.show();
  }
}

1

solved same method name but different class name [closed]