java练习---14
1 abstract class A{ 2 private String name; 3 public A(String name) { 4 this.name = name; 5 } 6 public String getName() { 7 return this.name; 8 } 9 public abstract void fun(); 10 } 11 class B extends A{ 12 public B(String name) { 13 super(name); 14 } 15 public void fun() { 16 System.out.println(super.getName()); 17 } 18 } 19 public class L { 20 public static void main(String[] args) { 21 // TODO Auto-generated method stub 22 B b = new B(null); 23 b.fun(); 24 } 25 } 26 import java.sql.Date; 27 28 @SuppressWarnings("unused") 29 public abstract class Y { 30 private String name; 31 private String Class; 32 private String date; 33 34 public String getName() { 35 return this.name; 36 } 37 public void setName(String name) { 38 this.name = name; 39 } 40 public String GetClass() { 41 return this.Class; 42 } 43 public void setClass(String Class) { 44 this.Class = Class; 45 } 46 public String getDate() { 47 return this.date; 48 } 49 public void setDate(String date) { 50 this.date = date; 51 } 52 public Y(String name,String Class,String date) { 53 this.name = name; 54 this.Class = Class; 55 this.date = date; 56 } 57 public Y() { 58 super(); 59 } 60 61 @Override 62 public String toString() { 63 return "Student [name=" + name + "]"; 64 } 65 public abstract String speak(); 66 67 } 68 import java.sql.Date; 69 @SuppressWarnings("unused") 70 public class H extends Y{ 71 private String matter; 72 public H(String name,String Class,String date,String matter) { 73 super(name,Class,date); 74 this.setMatter(matter); 75 } 76 @Override 77 public String speak() { 78 return "我叫 " + super.getName() + " 今年 " + super.GetClass() + " 身高 " + super.getDate() + " 体重 " + this.matter; 79 } 80 public String getMatter() { 81 return matter; 82 } 83 public void setMatter(String matter) { 84 this.matter = matter; 85 } 86 87 } 88 public class K { 89 90 public static void main(String[] args) { 91 // TODO Auto-generated method stub 92 Y stu = new H("罗元昊,","19岁了,","173cm,","52KG。"); 93 print(stu.speak()); 94 } 95 96 private static void print(String speak) { 97 System.out.println(speak); 98 99 } 100 101 }