Skip to content

Instantly share code, notes, and snippets.

@RadianSmile
Last active November 27, 2016 10:40
Show Gist options
  • Save RadianSmile/1bb94de6474a9d9f1c8971f94749554f to your computer and use it in GitHub Desktop.
Save RadianSmile/1bb94de6474a9d9f1c8971f94749554f to your computer and use it in GitHub Desktop.
  1. 宣告一個 car class 的做法:
class Car {  

  // property
  float speed ; 

  // Construct Method  
  Car (int initSpeed){  
    speed = initSpeed ;
  }
}

2 . 老師投影片所說 :

the constructor method is automatically called upon instantication (e.g. new)

「建構式」會在物件的建構時自動被呼叫。

目前你們只需要了解到:在 new 物件的時候會去呼叫建構式。

( 如果之後做得很深入,再去探索有哪些 new 之外的行為也會去呼叫建構式)

void setup (){
  Car car = new Car(10) // 這時候會執行 Construct Method  speed = initSpeed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment