Discuss / Java / 作业打卡

作业打卡

Topic source
public class PrimaryStudent extends Student {
	
	protected int grade;

	public PrimaryStudent(String name, int age, int score, int grade) {
		super(name, age, score);
		this.grade = grade;
	}
	
	public int getGrade() {
		return grade;
	}

}

public class Main {

	public static void main(String[] args) {
		Person p = new Person("小明", 12);
		Student s = new Student("小红", 20, 99);
		// TODO: 定义PrimaryStudent,从Student继承,新增grade字段:
		PrimaryStudent ps = new PrimaryStudent("小军", 9, 100, 5);
		System.out.println(ps.getName());
		System.out.println(ps.getAge());
		System.out.println(ps.getScore());
		System.out.println(ps.getGrade());
	}

}


  • 1

Reply