Discuss / Java / 作业

作业

Topic source

刘晋呈php

#1 Created at ... [Delete] [Delete and Lock User]
class HelloWorld
{
	public static void main(String[] args)
	{
		PrimaryStudent ming = new PrimaryStudent();
		ming.setName("xiaoming");
		ming.setAge(20);
		ming.setGrade(22);
		System.out.println("name is "+ming.getName()+", age is "+ming.getAge()+", grade is "+ming.getGrade());
	}
}
//Student
class Student
{
	protected String name;
	protected int age;
	
	//设置名字
	public void setName(String name)
	{
		this.name = name;
	}
	//设置年龄
	public void setAge(int age)
	{
		this.age = age;
	}
	//获取名字
	public String getName()
	{
		return this.name;
	}
	//获取grade
	public int getAge()
	{
		return this.age;
	}
}
//PrimaryStudent
class PrimaryStudent extends Student
{
	protected int grade;
	//设置grade 
	public void setGrade(int grade)
	{
		this.grade = grade;
	}
	//获取grade
	public int getGrade()
	{
		return this.grade;
	}
}

  • 1

Reply