Access class variable using Interface type

前端 未结 4 871
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-24 03:39

I\'ve following class

class MyClass implements Intrfc {

String pickmeUp = \"Its Me\";

public static void main(String[] args){

Intrfc ob = new MyClass();
ob.pi         


        
4条回答
  •  后悔当初
    2021-01-24 04:05

    In this definition:

    class MyClass implements Intrfc {
        String pickmeUp = "Its Me";
    }
    

    the field pickmeUp is not even a member of Intrfc interface, so there is no possibility to reach for it using just the interface. pickmeUp is a member of a concrete class - MyClass.

提交回复
热议问题