- class Person {
- public String name;
- public int age;
- public Person(String name, int age) {
- this.name = name;
- this.age = age;
- }
- public void sayHello() {
- System.out.println("我的名字是:" + name);
- System.out.println("我的年龄是:" + age);
- }
- }
- class Chinese extends Person
- {
- public Chinese(String name, int age) {
- super(name, age);
- }
-
- }
- public class Test8{
- /**
- * @param args
- */
- public static void main(String[] args) {
- Person person=new Person("alice", 20);
- person.sayHello();
- Chinese c=new Chinese("tom", 16);
- c.sayHello();
- }
- }
复制代码 |