Created
February 12, 2013 01:34
-
-
Save rawaludin/4759333 to your computer and use it in GitHub Desktop.
belajar visibility
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
class TamanBurung { | |
public static void main(String[] args) { | |
Burung Kakatua = new Burung(); | |
// Ini akan berhasil | |
Kakatua.jmlSayap = 2; | |
System.out.println("Jumlah sayap kakatua: "+Kakatua.jmlSayap); | |
// Ini akan error, karena private | |
// Kakatua.jmlKaki = 2; | |
// System.out.println("Jumlah kaki kakatua: "+Kakatua.jmlKaki); | |
// Ini akan berhasil, karena pakai setter dan getter | |
Kakatua.setJmlKaki(2); | |
System.out.println("Jumlah kaki kakatua: "+Kakatua.getJmlKaki()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment