//đây là class Sinh viên
public SinhVien(int mssv, String hoTen, float diemLT, float diemTH) throws Exception
{
if(mssv < 0)
throw new Exception("ma so sv khong duoc nho hon 0!");
if(hoTen==null) //kiểm tra họ tên rỗng
throw new Exception("ho ten sv khong duoc rong!");
if(diemLT < 0)
throw new Exception("diem ly thuyet khong duoc nho hon 0!");
if(diemTH < 0)
throw new Exception("diem thuc hanh khong duoc nho hon 0!");
}
//đây là class test sinh viên
public class SinhVien_Program {
public static void main(String[] args) {
try {
SinhVien sv= new SinhVien(0, "", 0, 0);
System.out.println(sv);
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
Mọi người cho em hỏi bên contructor SinhVien
em đã kiểm tra hoTen==null
mà sao ở class SinhVien_Progarm
em truyền vào ""(rỗng)
thì nó vẫn in ra đúng là
SinhVien [mssv=0, hoTen=null, diemLT=0.0, diemTH=0.0]