When I create a subclass of parent one , I cannot reach to variables and methods of subclass , note I have declare an object as instant of super class but I define it with subclass like this way :
class A {
public int x
}
class B extends A {
public int y;
}
public class C {
public static main(String arg[]) {
A obj=new B();
}
}
in main method I cannot reach to variable y of obj but for x I can , why ? even I have define this obj with B class still I cannot reach to B properties for obj . so I need to declare and define it with B class ! can any one explain ?