-7
类Person
{
私人字符串名称;
公共
字符串的ToString()
{
返回this.name;
}
}我们可以@Override派生类中的超类的公共方法吗?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); }
为什么不在发布问题之前尝试一下? –
如果你要编辑一个问题,请付出不少努力,但这看起来仍然很糟糕。 –
我试过了,我会添加错误代码试图访问较弱的访问privilages;被公开为 – user3128633