一个java编程错误
一个面试题问输出结果:
class Person {
class Man{
private String name;
private int age;
public int step;
Man(String s,int a){
name = s;
age =a;
step=0;
}
public void run(Man fast){
fast.step++;
}
}
public static void main(String[] args) {
Person p = new Person();
Man m = Person.new Man("tom",3);//错在哪?怎样改
m.step=25;
m.run(m);
System.out.println(m.step);
}
[解决办法]
改成:
Man m = p.new Man("tom",3);