Creating object with reference to Interface

后端 未结 6 858
自闭症患者
自闭症患者 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:40

    Compiler doesn't care about run-time. as far as the compiler is concerned, it checks if the reference type has a method called display in your interface type.

    methods declared in your sub-class or implementing class are not part of your super class/interface. thus you cannot invoke those methods which are declared in sub-class with super class/interface reference type.

提交回复
热议问题