class Main{
public static void main(String args[]){
A ob = new B();
System.out.println(ob.x);
}
}
class A{
int x;
public A(){
x = 10;
}
}
class B extends A{
int x;
public B(){
x = 20;
}
}
The output of the code is 10. I don't understand how this works. And why isn't B ob = new A()
valid? Also is there any real-world use of this?