Here is my code :
class A
{
int x=2,y=3;
}
class B extends A
{
//Blank
}
public class Test
{
public static void main(String args[])
{
A a=new A();
B b;
b=a;
System.out.println(b.x);
System.out.println(b.y);
}
}
When i'm trying to run this code, "incompatible types: A can't be converted to B" Error is shown.
And also when i'm trying to type-cast "a" into "B", ClassCastException is occured.
Is there any way to assign object to another object of different class in java ?