300 Câu hỏi trắc nghiệm lập trình Java có đáp án - Phần 3

Đoạn mã sau có lỗi biên dịch nào sau? class Student { protected String name; } public class Man extends Student { public static void main(String[] args) { Man m = new Man(); m.name = "John";

12/50

Đoạn mã sau có lỗi biên dịch nào sau?
class Student {
protected String name;
}
public class Man extends Student {
public static void main(String[] args) {
Man m = new Man();
m.name = "John";
}
}

name has protected access in Student.

Không có lỗi biên dịch

class Man has no attribute name.

class Man has no attribute or method name.

Giải thích

Chọn đáp án B.Vì: Thuộc tính name ở Student là protected, nên không lớp con Man được thừa kế.