This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Pet { | |
// name是private變數,Pet以外的物件無法直接取得此變數 | |
private string name; | |
// Pet類別的建構函式,參數是name | |
// 以這種寫法來初始化物件內部的變數name | |
public Pet( string name ) { | |
this.name = name; | |
} | |
// 但可以透過public方法取得name的值 | |
public string GetName() { | |
return name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment