-7
Person 클래스
{
개인 문자열 이름;
공공
문자열 toString()
{
반환 this.name;
}
}파생 클래스에서 수퍼 클래스의 public 메서드를 오버라이드 할 수 있습니까?class Student extends Person { private int no_of_courses; public @Override String toString() { return "Student " + super.toString(); } } class SuperDemo { public static void main(String[] args) { Person p = new Student("ABC,"XYZ"); System.out.println(p.toString()); } } Can we @Override a public method of super class in the derived class? Person class has Constructor Person(String name); Student class has constructor Student(String name) { super(name); }
질문을 게시하기 전에 시도해보십시오. –
질문을 편집하려면 노력을 기울이십시오. 여전히 끔찍한 모양입니다. –
나는 약한 액세스 권한에 액세스하려고 시도하는 오류 코드를 추가하려고합니다. public이었다 – user3128633