Question: I want to understand this:

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

```

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

Answer: 
Think about `p` as a view on the given object. You can view a `Dog` as an `Animal` (in which case you can e.g `feed()` it), or you can view it as a `Dog` (so you can get it to `bark()`). In other words, the variable's type that references an object will restrict what you can call on it, but does not change the type of the object.
p is an instance of `ChildClass` which of type `ParentClass` and 
using p you can call all the methods of ParentClass but you cannot call any method of ChildClass.
Example 

```
public class ParentClass{
public Person(){}
public void p(){
System.out.println("from p()");
}
}

public class ChildClass extends ParentClass{
public void c(){
System.out.println("from c()");
}

public static void main(String[] args) {
ParentClass p = new ChildClass();
ChildClass c = new ChildClass();
p.p(); //possible
p.c(); //not possible
c.c();  //possible
}

```

}