1. 程式人生 > >語言的基礎是一組記號和一組規則

語言的基礎是一組記號和一組規則

構造方法 運行 spa 品牌 let 包含 this text urn

是用於編寫計算機程序的語言。

語言的基礎是一組記號和一組規則。

根據規則由記號構成的記號串的總體就是語言。

在程序設計語言中,這些記號串就是程序。

程序設計語言包含三個方面,即語法、語義和語用。

語法表示程序的結構或形式,亦即表示構成程序的各個記號之間的組合規則,但不涉及這些記號的特定含義,也不涉及使用者。語義表示程序的含義,亦即表示按照各種方法所表示的各個記號的特定含義,但也不涉及使用著,語用表示程序與使用的關系。

  1 package Com.TableTest;
  2 
  3 class ElectricVehicle extends TableText_15 {
  4     //
私有屬性:電池品牌 5 private String diannchi; 6 // 公有的get***/set***方法完成屬性封裝 7 8 public String getDiannchi() { 9 return diannchi; 10 } 11 12 public void setDiannchi(String diannchi) { 13 this.diannchi = diannchi; 14 } 15 16 // 重寫運行方法,描述內容為:這是一輛使用**牌電池的電動車。其中**的數據由屬性提供
17 public String work() { 18 String str="這是一輛使用"+this.getDiannchi()+"牌電池的電動車"; 19 return str; 20 } 21 22 } 23 24 class Bicycle extends TableText_15 { 25 26 public Bicycle(String pinpai, String color) { 27 28 super.pinpai = pinpai; 29 super
.color = color; 30 } 31 // 重寫運行方法,描述內容為:這是一輛**顏色的,**牌的自行車。其中**的數據由屬性提供 32 public String work() { 33 String str="這是一輛"+this.getColor()+"顏色的 ,"+this.getPinpai()+"牌的自行車"; 34 System.out.println(str); 35 return str; 36 } 37 38 } 39 40 41 42 class TableText_15 { 43 // 私有屬性:品牌、顏色、輪子(默認2個)、座椅(默認 1個) 44 public String pinpai; 45 public String color; 46 private int wheelNum=2; 47 private int chairNum=1; 48 // 無參構造方法 49 public TableText_15() { 50 51 } 52 53 // 雙參構造方法,完成對品牌和顏色的賦值 54 public TableText_15(String pinpai, String color) { 55 super(); 56 this.pinpai = pinpai; 57 this.color = color; 58 } 59 // 四參構造方法,分別對所有屬性賦值 60 public TableText_15(String pinpai, String color, int wheelNum, int chairNum) { 61 super(); 62 this.pinpai = pinpai; 63 this.color = color; 64 this.wheelNum = wheelNum; 65 this.chairNum = chairNum; 66 } 67 68 // 公有的get***/set***方法完成屬性封裝 69 public String getPinpai() { 70 return pinpai; 71 } 72 73 public void setPinpai(String pinpai) { 74 this.pinpai = pinpai; 75 } 76 77 public String getColor() { 78 return color; 79 } 80 81 public void setColor(String color) { 82 this.color = color; 83 } 84 85 public int getWheelNum() { 86 return wheelNum; 87 } 88 89 public void setWheelNum(int wheelNum) { 90 this.wheelNum = wheelNum; 91 } 92 93 public int getChairNum() { 94 return chairNum; 95 } 96 public void setChairNum(int ChairNum){ 97 this.chairNum=ChairNum; 98 } 99 100 101 102 public static void main(String[] args){ 103 104 TableText_15 t=new TableText_15("borter","white"); 105 t.getColor(); 106 t.getPinpai(); 107 System.out.println(t.getColor()); 108 System.out.println(t.getPinpai()); 109 110 ElectricVehicle e=new ElectricVehicle(); 111 112 e.setDiannchi("borter"); 113 System.out.println(e.work()); 114 Bicycle b=new Bicycle("borter","white"); 115 System.out.println(b.work()); 116 117 118 } 119 120 } 121 122 123 124

語言的基礎是一組記號和一組規則