0

To Which concept below example belongs to: Method Overloading or Method Overriding???

package com.java.inheritance;
class A {
public void display(Integer i)
{
    System.out.println("in display of A"+i);
}
}

class B extends  A
{
    public void display(String i)
    {
        System.out.println("in display of B class"+i);
    }
}
/*public class InheritanceDemo{
    public static void main(String args[])
    {
        A a=new B();
        a.display("suchi");
    }
}*/

Please suggest with explaination.

  • 1
    You can actually try it: annotate `B.display()` with [`@Override`](https://docs.oracle.com/javase/7/docs/api/java/lang/Override.html). I'm pretty sure your compiler will complain. – Izruo Mar 14 '18 at 01:08
  • https://stackoverflow.com/questions/12374399/what-is-the-difference-between-method-overloading-and-overriding – Ivan Mar 14 '18 at 01:23

1 Answers1

0

This is an example of overloading, as you're applying the same signature except the number/kind of parameter(s).

If it had the same exact signature, it would be overriding.

Grey Haven
  • 380
  • 2
  • 13