public class Program {
public static void main(String[] args) {
Listener listener = new Listener();
listener.listen();
}
}
public class Listener {
ServerQuery query;
int test = 1;
public listen() {
query = new ServerQuery();
Channel ch = new Channel();
ch.dupa();
}
}
public class Channel extends Listener {
public dupa() {
System.out.print(test); // works fine
super.query.doSomething(); // null pointer
query.doSomething(); // null pointer
}
}
我无法访问“通道”类中的变量“查询”。谁能解释我为什么?