标签:main http 基础 student set type 技术 ati 类型
1 public class Person implements Serializable { 2 3 // 构造器初始化 4 public Person() { 5 name = "父类构造器初始化10。。。"; 6 System.out.println(this.name); 7 } 8 9 // 代码块初始化 10 { 11 String str3 = "父类代码块初始化7。。。"; 12 System.out.println(str3); 13 } 14 15 // 静态代码块初始化 16 static { 17 String str4 = "父类静态代码块初始化1。。。"; 18 System.out.println(str4); 19 } 20 21 /** 22 * 23 */ 24 private static final long serialVersionUID = -2803279990673361523L; 25 private String name;// 姓名 26 private int age;// 年龄 27 // 定义时普通变量初始化 28 private Order order = new Order("父类定义时初始化8。。。"); 29 // 定义时静态变量初始化 30 private static Dog dog = new Dog("父类定义时静态初始化2。。。"); 31 32 // 代码块初始化 33 { 34 String str1 = "父类代码块初始化9。。。"; 35 System.out.println(str1); 36 } 37 38 // 静态代码块初始化 39 static { 40 String str2 = "父类静态代码块初始化3。。。"; 41 System.out.println(str2); 42 } 43 44 public Person(String name, int age) { 45 this.name = name; 46 this.age = age; 47 } 48 49 public String getName() { 50 return name; 51 } 52 53 public void setName(String name) { 54 this.name = name; 55 } 56 57 public int getAge() { 58 return age; 59 } 60 61 public void setAge(int age) { 62 this.age = age; 63 } 64 65 public static Dog getDog() { 66 return dog; 67 } 68 69 public static void setDog(Dog dog) { 70 Person.dog = dog; 71 } 72 73 public Order getOrder() { 74 return order; 75 } 76 77 public void setOrder(Order order) { 78 this.order = order; 79 } 80 }
1 public class Student extends Person implements Serializable { 2 3 // 代码块初始化 4 { 5 String str1 = "子类代码块初始化11。。。"; 6 System.out.println(str1); 7 } 8 9 // 静态代码块初始化 10 static { 11 String str2 = "子类静态代码块初始化4。。。"; 12 System.out.println(str2); 13 } 14 15 /** 16 * 17 */ 18 private static final long serialVersionUID = -6642330930111509531L; 19 private float score;// 分数 20 private String grade;// 班级 21 // 定义时普通变量初始化 22 private Order order = new Order("子类定义时初始化12。。。"); 23 // 定义时静态变量初始化 24 private static Dog dog = new Dog("子类定义时静态初始化5。。。"); 25 26 // 代码块初始化 27 { 28 String str1 = "子类代码块初始化13。。。"; 29 System.out.println(str1); 30 } 31 32 // 静态代码块初始化 33 static { 34 String str2 = "子类静态代码块初始化6。。。"; 35 System.out.println(str2); 36 } 37 38 // 构造器初始化 39 public Student() { 40 grade = "子类构造器初始化14。。。"; 41 System.out.println(this.grade); 42 } 43 44 public float getScore() { 45 return score; 46 } 47 48 public void setScore(float score) { 49 this.score = score; 50 } 51 52 public String getGrade() { 53 return grade; 54 } 55 56 public void setGrade(String grade) { 57 this.grade = grade; 58 } 59 60 public Order getOrder() { 61 return order; 62 } 63 64 public void setOrder(Order order) { 65 this.order = order; 66 } 67 68 public static Dog getDog() { 69 return dog; 70 } 71 72 public static void setDog(Dog dog) { 73 Student.dog = dog; 74 } 75 }
1 public class Dog implements Serializable { 2 3 /** 4 * 5 */ 6 private static final long serialVersionUID = 2239821175446189806L; 7 private String kind; 8 private String name; 9 10 public Dog( String str) { 11 System.out.println(str); 12 } 13 14 public String getKind() { 15 return kind; 16 } 17 18 public void setKind(String kind) { 19 this.kind = kind; 20 } 21 22 public String getName() { 23 return name; 24 } 25 26 public void setName(String name) { 27 this.name = name; 28 } 29 30 }
1 public class Order implements Serializable { 2 3 /** 4 * 5 */ 6 private static final long serialVersionUID = 7441323999887439757L; 7 8 private String orderNo; 9 private String orderType; 10 11 public Order( String str) { 12 System.out.println(str); 13 } 14 15 public String getOrderNo() { 16 return orderNo; 17 } 18 19 public void setOrderNo(String orderNo) { 20 this.orderNo = orderNo; 21 } 22 23 public String getOrderType() { 24 return orderType; 25 } 26 27 public void setOrderType(String orderType) { 28 this.orderType = orderType; 29 } 30 }
1 public class Test { 2 public static void main(String[] args) { 3 Person p = new Person(); 4 Student stu = new Student(); 5 } 6 }
标签:main http 基础 student set type 技术 ati 类型
原文地址:http://www.cnblogs.com/yanglz528/p/7821687.html