今天学习面向对象时报错
报错
Non-static method 'show(yangyangjava.Phone)' cannot be referenced from a static context
代码
public class InstanceTest {
public static void main(String[] args) {
//匿名对象的使用
PhoneMall.show(new Phone());
}
}
原因
在使用类时,应先将类实例化
正确代码应为
public class InstanceTest {
public static void main(String[] args) {
//匿名对象的使用
PhoneMall mall = new PhoneMall();
PhoneMall.show(new Phone());
}
}