/*
父类 人 person 属性 姓名 年龄 功能 吃 睡
子类 学生 student 属性 学号 功能 学习
*/
import java.util.Scanner;
class StudentTest
{
//public StudentTest(){}
public static void main(String[] args)
{
Student a = new Student();
a.eat();
a.study();
a.sleep();
Scanner sc = new Scanner(System.in);
//int p = sc.nextInt();
a.setAge(18);
a.setName("林青霞");
a.setStudentNmb(20233);
System.out.println(a.getAge());
System.out.println(a.getName());
System.out.println(a.getStudentNmb());
System.out.println("Hello World!");
}
}
abstract class Person
{
private String name;
private int age;
public Person(){}
public Person(String name,int age)
{
this.name = name;
this.age = age;
}
public void sleep()
{
System.out.println("睡觉");
}
//抽象方法
public abstract void eat();
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setAge(int age)
{
this.age = age;
}
public int getAge()
{
return age;
}
}
class Student extends Person
{
//成员变量
private int studentNmb;
//构造方法
public Student(){}
public Student(int studentNmb)
{
this.studentNmb = studentNmb;
}
//get/set
public void setStudentNmb(int studentNmb)
{
this.studentNmb = studentNmb;
}
public int getStudentNmb()
{
return studentNmb;
}
//成员方法
public void study()
{
System.out.println("学生爱学习");
}
public void eat()
{
System.out.println("学生爱吃饺子");
}
}
|
|