Code mẫu về lớp trừu tượng abstract java

Code: Java 02/03/2021 02:27

abstract public class SinhVien {
        public String hoTen;
        abstract public double getDiem();
}


===========================================
public class SinhVienIT extends SinhVien {
    double diemJava;
    double diemC;
    @Override
    public double getDiem() {
        return  (this.diemJava + this.diemC);
    }
}

==========================================
public class Main {
    public static void main(String[] args) {
        SinhVienIT sinhVienIT = new SinhVienIT();
        sinhVienIT.diemC = 7;
        sinhVienIT.diemJava = 8;
        double tong = sinhVienIT.getDiem();
        System.out.println("Tong diem: " + tong);
    }
}