/*子类继承了父类的属性和方法*/
class Person{
String name;
String sex;
int age;
void speak(){
System.out.println("这是person说话的方法");
}
}
public class Student extends Person{
int num;
void speak(){
System.out.println("这是stu说话的方法");
}
public static void main(String[] args) {
Student stu=new Student();
stu.name="liu";
stu.speak();
System.out.println(stu.name);
}
}
继承
最新推荐文章于 2025-05-11 15:58:03 发布
911

被折叠的 条评论
为什么被折叠?



