对super的运用

package 继承运用;
class Student{
 String studentclass="学生";
 int id;
 String name;
 String boredTime;
 public Student(int id, String name, String boredTime) {
  this.id=id;
  this.name=name;
  this.boredTime = boredTime;
 }
 public void study() {
  System.out.println("好好学习,天天向上!");
 }
 public void eat() {
  System.out.println("多喝牛奶!长高高哦");
 }
}
class smallStudent extends Student
{   String smallStudent="小学生";
 public  smallStudent(int id,String name,String boredTime) {
  super(id,name,boredTime);
 }
 public void reprot() {
  System.out.println("我是"+studentclass+"中的"+smallStudent);
 }
}
class bigStudent extends Student
{
   String bigStudent = "大学生";
   public bigStudent(int id , String name,String boredTime) {
    super(id,name,boredTime);
   }
   public void reprot() {
    System.out.println("我是"+studentclass+"中的"+bigStudent);
   }
}
public class Dome3 {
 public static void main(String []args) {
 Student s1=new Student(10086,"狗蛋","2010年3月2日");
 System.out.println("学号"+s1.id);
 System.out.println("姓名"+s1.name);
 System.out.println("出生时间"+s1.boredTime);
 s1.study();
 s1.eat();
 smallStudent s2 = new smallStudent(10010,"蠢蛋","2005年3月2日");
 s2.reprot();
 System.out.println("学号"+s2.id);
 System.out.println("姓名"+s2.name);
 System.out.println("出生时间"+s2.boredTime);
 s2.study();
 s2.eat();
 bigStudent s3 =new bigStudent(110,"狗屎","2000年3月2日");
 s3.reprot();
 System.out.println("学号"+s3.id);
 System.out.println("姓名"+s3.name);
 System.out.println("出生时间"+s3.boredTime);
 s3.study();
 s3.eat();
 
}
}

转载于:https://www.cnblogs.com/0929-luoyang/p/10842114.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值