import java.net.StandardSocketOptions;
class Person{ //定义了一个人的父类
String name;
char sex;
Person(String n){ //构造方法
name=n;
}
Person(String n,char s){ //构造方法的重载
this(n);
sex=s;
}
void show(){
System.out.println("姓名是"+name+",性别是"+sex);
}
}
class Student extends Person{ //子类
int num;
double score;
Student(String n,char s,int num,double score){
super(n,s);
this.num=num;
this.score=score;
}
void show(){ //覆盖
super.show();
System.out.println("学号是"+num+",成绩是"+score);}
}
public class Di143 {
String name;
char sex;
Person(String n){ //构造方法
name=n;
}
Person(String n,char s){ //构造方法的重载
this(n);
sex=s;
}
void show(){
System.out.println("姓名是"+name+",性别是"+sex);
}
}
class Student extends Person{ //子类
int num;
double score;
Student(String n,char s,int num,double score){
super(n,s);
this.num=num;
this.score=score;
}
void show(){ //覆盖
super.show();
System.out.println("学号是"+num+",成绩是"+score);}
}
public class Di143 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Student stu1=new Student("韩蕾",'女',1,85); //初始化
stu1.show();
Person p=new Person("韩蕾",'女');
p.show();
}
// TODO Auto-generated method stub
Student stu1=new Student("韩蕾",'女',1,85); //初始化
stu1.show();
Person p=new Person("韩蕾",'女');
p.show();
}
}
运行结果
姓名是韩蕾,性别是女
学号是1,成绩是85.0
姓名是韩蕾,性别是女
学号是1,成绩是85.0
姓名是韩蕾,性别是女