Java 2017.11.13 杨浩宁作业

package top.hyself;

abstract class A{
    private String name;
    public A(String name) {
        this.name = name;
    }
    public String getName() {
        return this.name;
    }
    public abstract void fun();
}
class B extends A{
    public B(String name) {
        super(name);
    }
    public void fun() {
        System.out.println(super.getName());
    }
}
public class This {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        B b = new B(null);
        b.fun();
    }
}

package top.hyself;

import java.sql.Date;

public abstract class Student {
    private String name;
    private String Class;
    private String date;

public String getName() {
    return this.name;
}
public void setName(String name) {
    this.name = name;
}
public String GetClass() {
    return this.Class;
}
public void setClass(String Class) {
    this.Class = Class;
}
public String getDate() {
    return this.date;
}
public void setDate(String date) {
    this.date = date;
}
public Student(String name,String Class,String date) {
    this.name = name;
    this.Class = Class;
    this.date = date;
}
public Student() {
    super();
}

@Override
public String toString() {
    return "Student [name=" + name + "]";
}
public abstract String speak();

}
package top.hyself;

import java.sql.Date;

public class Offence extends Student{
    private String matter;
    public Offence(String name,String Class,String date,String matter) {
        super(name,Class,date);
        this.setMatter(matter);
    }
    @Override
    public String speak() {
        return "我叫:" + super.getName() + " 班级:" + super.GetClass() + " 时间:" + super.getDate() + " 事由:" + this.matter;
    }
    public String getMatter() {
        return matter;
    }
    public void setMatter(String matter) {
        this.matter = matter;
    }
    
}
package top.hyself;

public class Demo {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Student stu = new Offence("匡志伟","网站班","2017.11.13","搞事");
        print(stu.speak());
    }

    private static void print(String speak) {
        System.out.println(speak);
        
    }

}

Java 2017.11.13 杨浩宁作业_第1张图片

你可能感兴趣的:(Java 2017.11.13 杨浩宁作业)