·类和对象的扩展
class Human { String name; int age; Human(){} Human(String name,int age){ this.name = name; this.age = age; } viod walk(){ System.out.println(name + "慢慢走"); } } class Child extends Human{ String schoolName; Child(String name,int age,String school){ super(name,age); this.schoolName = school; } void study(){ System.out.println(name + "写数学作业"); } void walk(){ System.out.println(name + "蹦蹦跳跳地走"); } } } public class Demo3{ public static void main(String[] args){ Human h = new Human("小明爸爸",35); h.walk(); Child c = new Child("小明",8,"实验小学"); c.study(); c.walk(); } }·用记事本更改编码方式后,仍然出现问题
时间: 2024-10-12 15:20:02