Rohann Rai

Rohann Rai

  • 2.1k
  • 14
  • 468

Function overloading vs function overriding

Oct 7 2021 4:42 PM

Consider the following piece of code

public class SuperClass
{//label 1void function(int a){System.out.println(a);}
}public class SubClass extends SuperClass
{//label 2void function(int a){a++;System.out.println(a);}//label 3void function(float a){System.out.println(a);}   
}

From what I have learnt, label 2 is an example of function overriding because a superclass method is being re-written in the sub class with its own implementation, while label 3 is a form of function overloading because the parameters are different while the function name is same.

My question is if label 3 is in fact function overloading, which function is it overloading? Label 1 or label 2?

My theory is that label 3 is overloading label 2 because they are part of the same class.

This is only a conceptual question I had while learning polymorphism in Java.

Any help would be appreciated.

I was referring to this article -


Answers (2)