I'm recently learning java, i came from PHP background. I'm stuck with a concept that i didn't quite understand, so we have a parent class called (Animal) and a child class called (Wolf), from what i know, when you want to create a new instance of the class (Wolf) for example, this is the code you write:
Wolf wolf1 = new Wolf();
But in the books i found this second way that also get you same results:
Animal wolf1 = new Wolf();
Second thing, is when you have an interface (let's call it (myInterface)) and the class (Wolf) is implementing it, i found a third way of instanciating the class (Wolf):
myInterface wolf1 = new Wolf();
The questions are: why this works? and why doing it in the first place? is there a simple example that makes it clear why you should instanciate your class using the second and the third way?