Question: I want to understand this:

```
ParentClass p=new ChildClass(); 
//Here ChildClass extends ParentClass

```

Is `p` object of `ParentClass` or of `ChildClass`?

Answer: 
> 
> Is p object of ParentClass or of ChildClass?
> 
> 
> 

`p` is an instance of `ChildClass`. Any instance of `ChildClass` is also an instance of `ParentClass`. The other way around is not true.

**EDIT:**

If you were to call `p.getClass()`, that will return `ChildClass`.
`p` is not instance at all. it is just reference of type `ParentClass` that is pointing to object of `ChildClass` on heap memory.

`Objects` live on heap while references can be on stack memory or in other objects on heap. think `reference` as pointers in c/c++ with some additional functionality. 

Your example is of inheritance where reference of type `ParentClass` can point to `ChildClass` object.