继承的格式: class 子类名 extends 父类名{}
如何使用继承:属于同一种类的事物和方法,可以归于同一种类
1 package debug; 2 3 class Person{ 4 public static void eat(){ 5 System.out.println("吃饭"); 6 } 7 8 public static void sleep(){ 9 System.out.println("睡觉"); 10 } 11 12 } 13 14 class Student extends Person { 15 16 } 17 18 19 class Teacher extends Person { 20 21 } 22 23 public class ExtendDemo { 24 public static void main(String[] args) { 25 Student s = new Student(); 26 s.eat(); 27 s.sleep(); 28 29 Teacher t = new Teacher(); 30 t.eat(); 31 t.sleep(); 32 } 33 }