2 wallyone wallyone 于 2014.09.28 15:46 提问

实际参数列表与形式参数列表不同 ?为何会如此?

class Person
{
String name;
int age;
public void Person(String name,int age){
this.name = name;
this.age = age;
}
public void say(){

System.out.println("姓名"+ this.name +" 年龄"+ this.age);
}
}

public class AddPerson{
public static void main(String[] args){
Person p1 = new Person("王五",23);

Person p2 = new Person("赵六",34);
Person p3 = new Person();
p3.name = "张三";
p3.age = 32;

    p1.say();
    p2.say();
    p3.say();
}

}
CSDN移动问答

1个回答

tony_328427685
tony_328427685   2014.09.29 10:48

public void Person(String name,int age){
this.name = name;
this.age = age;
}
这个地方错了,应该是这样的
public Person(String name,int age){
this.name = name;
this.age = age;
}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!