创建学生类并赋予特性
石先森第71楼
class student{ String grade="学生"; int num; String name; String born; student(int num,String name,String born){ this.num=num; this.name=name; this.born=born; } public void eat(){ System.out.println("吃嘛嘛香"); } public void study(){ System.out.println("好好学习,天天向上"); } } class Pupil extends student{ String grade="小学生"; Pupil(int num,String name,String born){ super(num,name,born); } public void report(){ System.out.println("我是"+super.grade+"中的"+grade); } } public class Demo1 { /** * @param args */ public static void main(String[] args) { Pupil p1=new Pupil(10001,"lili","1999年12月1日"); p1.eat(); p1.study(); p1.report(); } } |