200+ câu trắc nghiệm Java cơ bản có đáp án - Phần 5

Đoạn mã sau có lỗi biên dịch nào? class Student { public int getAge(){ return 10; } } public class Man extends Student{ public int getAge(int added) { return super.getAge()+added; } }

14/30

Đoạn mã sau có lỗi biên dịch nào?

class Student {

public int getAge(){

return 10;

}

}

public class Man extends Student{

public int getAge(int added) {

return super.getAge()+added;

}

}

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

Có lỗi biên dịch: getAge() in Student and Man can not have the same access modifier.

Có lỗi biên dịch:call to super, must be the first in constructor in class Man.

Có lỗi biên dịch: getAge() in Student and Man can not have the same access arguments.

Giải thích

Chọn đáp án A

Vì:

getAge() ở Student và Man có arguments khác nhau, nên chúng là các phương thức khác nhau.