abstract关键字的使用



package day11;

abstract class Student{
 int id;
 String name;
 
 public Student() {}
 
 abstract public void study();
 abstract public void introduceYourself();
}

class JavaNormal extends Student {
 
 public JavaNormal(int id,String name) {
  this.id = id;
  this.name = name;
 }
 
 @Override
 public void introduceYourself() {
  System.out.println("我的id是" + id + "我的名字是" + name);
 }
 
 @Override
 public void study() {
  System.out.println("我们是普通班的学生,我们学的是马克思列宁主义");
 }
 
}

class JavaBasis extends Student {
 
 public JavaBasis(int id,String name) {
  this.id = id;
  this.name = name;
 }
 
 @Override
 public void introduceYourself() {
  System.out.println("我的id是" + id + "我的名字是" + name);
 }
 
 @Override
 public void study() {
  System.out.println("我们是java基础班的学生,学的是JavaEE");
 }
 
}

class JavaWork extends Student {
 
 public JavaWork(int id,String name) {
  this.id = id;
  this.name = name;
 }
 
 @Override
 public void introduceYourself() {
  System.out.println("我的id是" + id + "我的名字是" + name);
 }
 
 @Override
 public void study() {
  System.out.println("我们是java就业班的学生,我们学的是Java + SSH");
 }
}

public class Work1 {
 public static void main(String[] args) {
  JavaNormal normal = new JavaNormal(001,"洋河");
  normal.introduceYourself();
  normal.study();
  
  JavaBasis basis = new JavaBasis(002,"闪水");
  basis.introduceYourself();
  basis.study();
  
  JavaWork work = new JavaWork(003,"紫菓");
  work.introduceYourself();
  work.study();
  
 }
}

你可能感兴趣的:(Java语言)