java定义两个类,Person类是父类,具有姓名、性别两个属性以及显示它们一个行为。
java定义两个类,Person类是父类,具有姓名、性别两个属性以及显示它们一个行为.Student类是Person类的子类,继承了Person类的所有成员,同时增加了自...
java定义两个类,Person类是父类,具有姓名、性别两个属性以及显示它们一个行为.Student类是Person类的子类,继承了Person类的所有成员,同时增加了自己的新属性:学号和成绩,以及两个新行为;设置4个属性值的方法、显示学号和成绩的方法。尽快,对的给分。谢谢了
展开
3个回答
展开全部
楼主,程序如下:
Person类:
public class Person {
private String name;
private int sex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
}
===================华丽的分割线======================
Studnet类:
public class Student extends Person {
private int sno;
private float score;
public int getSno() {
return sno;
}
public void setSno(int sno) {
this.sno = sno;
}
public float getScore() {
return score;
}
public void setScore(float score) {
this.score = score;
}
//设置四个属性值的方法
public void setValue(String name,int sex,int sno,float score)
{
this.setName(name);
this.setSex(sex);
this.sno = sno;
this.score = score;
}
//显示学号、成绩的方法
public void show()
{
System.out.println(sno + "\t" + score);
}
//测试
public static void main(String[] args) {
Student student = new Student();
student.setValue("Jacky", 1, 123456, 99.8f);
student.show();
}
}
有问题欢迎提问,满意请采纳!
Person类:
public class Person {
private String name;
private int sex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
}
===================华丽的分割线======================
Studnet类:
public class Student extends Person {
private int sno;
private float score;
public int getSno() {
return sno;
}
public void setSno(int sno) {
this.sno = sno;
}
public float getScore() {
return score;
}
public void setScore(float score) {
this.score = score;
}
//设置四个属性值的方法
public void setValue(String name,int sex,int sno,float score)
{
this.setName(name);
this.setSex(sex);
this.sno = sno;
this.score = score;
}
//显示学号、成绩的方法
public void show()
{
System.out.println(sno + "\t" + score);
}
//测试
public static void main(String[] args) {
Student student = new Student();
student.setValue("Jacky", 1, 123456, 99.8f);
student.show();
}
}
有问题欢迎提问,满意请采纳!
展开全部
public class Person {
private String name;
private String gender;
public String getName() {
System.out.println(name);
return name;
}
public void setName(String name) {
this.name=name;
}
public String getGender() {
System.out.println(gender);
return gender;
}
public void setGender(String gender) {
this.gender=gender;
}
}
public class Student extends Person {
private String number;
private Integer score;
public String getNumber() {
System.out.println("学号"+number);
return number;
}
public void setNumber(String number) {
this.number=number;
}
public Integer getScore() {
System.out.println("成绩"+score);
return score;
}
public void setScore(Integer score) {
this.score=score;
}
public void sayHello() {
System.out.println("新行为1");
}
public void sayHello2() {
System.out.println("新行为2");
}
public static void main(String[] args) {
Student s1=new Student();
s1.setName("小明");
s1.setGender("男");
s1.setNumber("01");
s1.setScore(90);
s1.getName();
s1.getGender();
s1.getNumber();
s1.getScore();
s1.sayHello();
s1.sayHello2();
}
}
private String name;
private String gender;
public String getName() {
System.out.println(name);
return name;
}
public void setName(String name) {
this.name=name;
}
public String getGender() {
System.out.println(gender);
return gender;
}
public void setGender(String gender) {
this.gender=gender;
}
}
public class Student extends Person {
private String number;
private Integer score;
public String getNumber() {
System.out.println("学号"+number);
return number;
}
public void setNumber(String number) {
this.number=number;
}
public Integer getScore() {
System.out.println("成绩"+score);
return score;
}
public void setScore(Integer score) {
this.score=score;
}
public void sayHello() {
System.out.println("新行为1");
}
public void sayHello2() {
System.out.println("新行为2");
}
public static void main(String[] args) {
Student s1=new Student();
s1.setName("小明");
s1.setGender("男");
s1.setNumber("01");
s1.setScore(90);
s1.getName();
s1.getGender();
s1.getNumber();
s1.getScore();
s1.sayHello();
s1.sayHello2();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
class Person {
public String name;
public String sex;
//get 和 set 方法 可以再eclipse中直接生成,这里就不写了
get()
set()
public void fafang(){
---------------------------
}
}
class Student extends Person {
public String numner;
public String chengJi;
//get 和 set 方法
get()
set()
public void xingWei1() {
----------------------
}
public void xingWei2() {
----------------------
}
}
public String name;
public String sex;
//get 和 set 方法 可以再eclipse中直接生成,这里就不写了
get()
set()
public void fafang(){
---------------------------
}
}
class Student extends Person {
public String numner;
public String chengJi;
//get 和 set 方法
get()
set()
public void xingWei1() {
----------------------
}
public void xingWei2() {
----------------------
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询