
what is exact meaning for the statement,
A a1=new B();

Hi,
Here is two classes A and B. A is super class and B is sub class. Here is the code example:
public class A
{
public int i=40;
public void print()
{
System.out.println("A");
}
}
public class B extends A
{
public int i=20;
public void print()
{
System.out.println("B");
}
public static void main(String args[])
{
A a = new B();
A a1 = new A();
System.out.println(a.i);
System.out.println(a1.i);
a.print();
a1.print();
}
}
With the help of following line:
A a = new B();
You are creating the object of subclass Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.