'How Does Type Casting in Java Actually Work? [duplicate]

Suppose A is a superclass of B and each have property i with default value is 0.

B b = new B();
System.out.print(b.i);
A a = b;
a.i = 3;
System.out.print(b.i);

Why the output is 00 not 03?

Does casting create new object?

Edit :

These are A and B :

class A {
    int i;
}
class B extends A {
    int i;
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source