```
public class A
{  }

public class B extends A
{
  public void add()
  {
   System.out.println("add in B");
  }
}

```

Now here if we call add in following way hen it gives an error:
A a1 = new B;
a1.add();

But when we add the add() method in class A and then call in the similar fashion then add() method of child class is called. 

i.e.

```
public class A
{
  public void add()
  {
   System.out.println("add in A");
  }
}

public class B extends A
{
  public void add()
  {
   System.out.println("add in B");
  }
}

```

call:

```
A a1 = new B;
a1.add();

```

output:

> 
> add in B
> 
> 
> 

Why is it so?