Q:

How java casting work, is it change the state of Object or create new Object?

I have a method dummy with A as class parameter, but i need to pass instance of subclasses  B to that method. I know from:
Does Java casting introduce overhead? Why?
that downcasting in java have overhead. Most of my code deal with subclass B so i dont use downcasting for this purpose. Instead i use temporal instance variable cc for that purpose. But this is not make a change for object of subclass m. I need change in variable cc avaliable too for instance variable m. This is my code:
public class TestCast {

    public TestCast() {
        B m = new B(12, 3);
        dummy(m);
        A cc = m;
        dummy(cc);
        System.out.println(m.a);
        System.out.println(cc.a);
    }

    public void dummy(A t) {
        t.a = 22222;
    }

    public static void main(String[] args) {
        new TestCast();
    }
}

class A {
    public int a = 0;

    public A(int a) {
        this.a = a;
    }
}

class B extends A {

    public int a;
    public int b;

    public B(int a, int b) {
        super(a);
        this.a = a;
        this.b = b;
    }
}

with output
12
22222

A:

In your particular example, both the parent and child classes declared a field with name a. In this case, the child variable hides the parent variable.
Also, variables/fields are not polymorphic entities like methods. They are accessed by the static type of a reference.
In other words, the field access
A var = new A(10);
var.a; // returns 10

And the field access
A var = new B(1501, 10); 
var.a; // also returns 10

but
A var = new B(1501, 10); 
var.a; // returns 10
((B)var).a; // returns 1501

because you access a on a reference with static type B.
In your method
public void dummy(A t) {
    t.a = 22222;
}

The static type of t is A so you will modify the value of the parent class variable.

