猿问

为什么输出大儿子和二儿子的名字一样。


public class FamilyPerson {

static String surname;

String name;

public static void setSurname(String s){

surname = s;

}

public void setName(String s){

name = s;

}

}

 

public class MainClass {

public static void main(String args[]){

FamilyPerson.surname="李";

FamilyPerson father,sonOne,sonTwo;

father = new FamilyPerson();

sonOne = new FamilyPerson();

sonTwo = new FamilyPerson();

father.setName("向阳");

sonOne.setName("抗日");

sonTwo.setName("抗战");

System.out.println("父亲:"+father.surname+father.name);

System.out.println("大儿子:"+sonOne.surname+sonOne.name);

System.out.println("二儿子:"+sonTwo.surname+sonOne.name);

father.surname="张";

System.out.println("父亲:"+father.surname+father.name);

System.out.println("大儿子:"+sonOne.surname+sonOne.name);

System.out.println("二儿子:"+sonTwo.surname+sonOne.name);

}

}


九天安属
浏览 1457回答 3
3回答
随时随地看视频慕课网APP

相关分类

Java
我要回答