The document discusses object oriented programming (OOP) and some of its key concepts including objects, abstraction, encapsulation, polymorphism, and inheritance. It provides examples to illustrate encapsulation, including defining private and public access modifiers in a class. Encapsulation allows restricting access to some class members like fields and methods, while public access makes members accessible anywhere.
3. Mengapa Perlu OOP?
Top-Down/Bottom-Up Programming
Spaghetti Code
Structured Programming Tidak reusable
Procedural Programming Sudah reusable,
tetapi belum merepresentasikan object, belum
modular, dan hard-to-manage
4. Object Oriented Programming
Untuk itu dikembangkan OOP
Konsep dasar OOP:
Objek
Abstraksi
Enkapsulasi
Polimorfisme
Inheritance
10. Private
Definition: The type or member can be accessed only by code in
the same class or struct.
Contoh:
Class Mahasiswa(){
private string nik;
private string nama;
private string getNama(){
return nama;
}
}
Class Universitas(){
public static void main(String [] args){
Mahasiswa mhs = new Mahasiswa();
System.out.print(mhs.nama);
}
}
11. Public
Definition: The type or member can be
accessed by any other code in the same
assembly or another assembly that references
it.
12. Protected
Definition: The type or member can be
accessed only by code in the same class or
struct, or in a class that is derived from that
class.
Penggunaan: Lebih banyak pada kasus
turunan class (Inheritance)