Q:

Calling member with Sub class reference

I'm calling ChildTest class methods with ChildTest reference only i.e. 
ChildTest child = new ChildTest(); // not dynamic dispatching. 

My question is why child.foo() output is Test foo called 10
class Test {
    int x = 10;

    public void foo() {
        System.out.println("Test foo called " + x);

    }

    public static void main(String args[]) {
        ChildTest child = new ChildTest();

        System.out.println(child.x);
        child.foo();
        child.bar();
    }
}

class ChildTest extends Test {
    int x = 20;

    public void bar() {
        System.out.println("ChildTest Bar called " + x);
    }
}

A:

Variables cannot be overridden in Java, so what you have done is that you have hidden the original x variable.  
The fact that you have added a variable x in your ChildTest class and given it the value 20 does not affect the variable x from your Test class, which will still be 10.
The method foo() still resides in the Test class, which means that it will use the x variable declared in that class. If you want to see a different output for a call from a ChildTest reference, you can add a getX() method and override it: 
class Test {
    public int getX() {
        return 10;
    }
    public void foo() {
        System.out.println("Test foo called " + getX());
    }
    ...

class ChildTest extends Test {
    @Override
    public int getX() {
        return 20;
    }
    ...

