【发布时间】:2018-08-03 13:37:16
【问题描述】:
我可以知道如何使用/调用年龄方法吗?这是Student类。
class Student {
public static void address(){
System.out.println("streetB");
}
}
public class School {
public static void main(String[] args) {
Student gg = new Student() {
public void age() {
System.out.println("9");
}
};
//how to call age() method here?
}
}
【问题讨论】:
-
gg.age(),和其他方法一样吗? -
@cricket_007 不起作用,
Student类没有age方法,仅适用于address或使用var声明gg时
标签: java object anonymous-class