Creating object with reference to Interface

后端 未结 6 855
自闭症患者
自闭症患者 2021-02-04 22:08

A reference variable can be declared as a class type or an interface type.If the variable is declared as an interface type, it can reference any object of any class that impleme

6条回答
  •  礼貌的吻别
    2021-02-04 22:49

    wherever the method signature reside reference of that interface will not give any error. In your example your method sysout() is in interface so reference of the interface will not give any error, but for method displayName() interface reference gives an error. For that you have to use your class reference.

提交回复
热议问题