继承extends
class Person{ String name; int age; void eat(){ System.out.println("吃饭"); } void introduce(){ System.out.println("我的名字是"+name+",我的年龄是"+age); } }
class Student extends Person{ }
Student继承Person,测试:
class Test{ public static void main(String args[]){ Student student=new Student(); student.name="张三"; student.age=18; student.eat(); student.introduce(): } }