求解下面的Java填空题,//的地方是需要填空的。谢谢

publicclassPerson{protectedStringname;protectedcharsex;//this.name=name;this.sex=sex;... public class Person {
protected String name;
protected char sex;

//
this.name = name;
this.sex = sex;
}

String name() {
return name;
}

char sex() {
return sex;
}

public String toString() {
String s = new String(name + "(sex:" + sex + ")");
return s;
}
}

public class Student extends Person{
protected String id;
Student(String name,char sex){
//
}

Student(String name,char sex,String id){
super(name,sex);
this.id = id;
}

public String toString() {
String s = new String(name + "(sex:" + sex);
//
s += ")";
return s;
}

//
this.id = id;
}

//

}

public class Main {
public static void main(String[] args) {
Person frank = new Person("Frank",'M');
Student alice = new Student("Alice",'F');
System.out.println("frank: " + frank);
System.out.println("alice: " + alice);
Person tom = alice;
System.out.println("tom: " + tom);
//
System.out.println("tom: " + tom);
}
}
展开
 我来答
qick
2020-12-23 · TA获得超过984个赞
知道小有建树答主
回答量:541
采纳率:100%
帮助的人:164万
展开全部

//Person

package test20201223;


public class Person {

protected String name;

protected char sex;

//这里应该是一个构造方法,或者set方法,

//构造方法

public Person(){}

public Person(String name,char sex){

this.name = name;

this.sex = sex;

}

//set方法

public void setPerson(String name,char sex){

this.name = name;

this.sex = sex;

}

String name() {

return name;

}

char sex() {

return sex;

}

public String toString() {

String s = new String(name + "(sex:" + sex + ")");

return s;

}

}


//Student


package test20201223;

public class Main {

public static void main(String[] args) {

Person frank = new Person("Frank",'M');

Student alice = new Student("Alice",'F');

System.out.println("frank: " + frank);

System.out.println("alice: " + alice);

Person tom = alice;

System.out.println("tom: " + tom);

//改变tom属性

tom.setPerson("tom", 'M');

System.out.println("tom: " + tom);

}

}


//Main


package test20201223;

public class Main {

public static void main(String[] args) {

Person frank = new Person("Frank",'M');

Student alice = new Student("Alice",'F');

System.out.println("frank: " + frank);

System.out.println("alice: " + alice);

Person tom = alice;

System.out.println("tom: " + tom);

//改变tom属性

tom.setPerson("tom", 'M');

System.out.println("tom: " + tom);

}

}

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式