Instantiating interfaces in Java

前端 未结 14 1588
南笙
南笙 2020-12-07 21:08

I have this interface:

public interface Animal {
    public void Eat(String name);
}

And this code here implements the interface:



        
14条回答
  •  孤城傲影
    2020-12-07 21:16

    The Interface Animal acts as the data type to the class Dog. You're actually instantiating the Dog class not the interface or it's data type.

提交回复
热议问题