What is the actual need of casting?

In reply to Harin Maniyar:

To explain the results your are seeing, when constructing a class B object, you get all the members of class B and class X. You have two x variables.

You may want to read this as well as the links it contains.