I have this interface:
public interface Animal {
public void Eat(String name);
}
And this code here implements the interface:
No it is not - you are instantiating a Dog
, but since a Dog
is an Animal
, you can declare the variable to be an Animal
. If you try to instantiate the interface Animal
it would be:
Animal baby2 = new Animal();
Try that, and watch the compiler scream in horror :)
Here it is just referencing to the interface but instantiation is done by the class only. for e.g
Animanl a = new Dog Animal a - variable is referenced new Dog - now Memory is allocated