/*子类继承了父类的属性和方法*/
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-04-04 13:54:46 发布