Discuss / Java / 练习

练习

Topic source
public class Main{
	public static void main(String[] args) {
		PrimaryStudent ps = new PrimaryStudent("小军", 9, 100, 5);
		System.out.println(ps.age+" "+ps.name+" "+ps.score+" "+ps.grade);
	}
}

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

class Student extends Person{
	protected int score;
	public Student(String name, int age, int score) {
		super(name,age);
		this.score = score;
	}
	
	
}
//定义PrimaryStudent,从Student继承,并新增一个grade字段:
class PrimaryStudent extends Student{
	protected int grade;
	public PrimaryStudent(String name, int age, int score,int grade) {
		super(name,age,score);
		this.grade = grade;
	}
}

  • 1

Reply