WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions darmawanabi/oop_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Employee:

# mendefinisikan atribut diluar konstruktor
empCount = 0

def __init__(self, name, salary):
self.name = name
self.salary = salary
# name dan salary merupakan atribut yang didefinisikan didalan cons

Employee.empCount += 1

def displayCount(self):
print("Total Karyawan : ", Employee.empCount)

def displayEmployee(self):
print("Nama : ", self.name)
print("Gaji : ", self.salary)

emp1 = Employee("Darmawan Abinugroho", 1000)
emp1.displayEmployee()
emp1.displayCount()
20 changes: 20 additions & 0 deletions darmawanabi/oop_encapsulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class computer:

def __init__(self):
self.maxPrice = 750

def sell(self):
print("Harga Jual : {}".format(self.maxPrice))

def setMaxPrice(self, price):
self.maxPrice = price

comp = computer()
comp.sell()

comp.maxPrice = 1000
comp.sell()

# gunakan fungsi setter
comp.setMaxPrice(2000)
comp.sell()
28 changes: 28 additions & 0 deletions darmawanabi/oop_inheritance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Bird:

def __init__(self):
print("Bird Initialization")

def siapaYa(self):
print("Bird")

def swim(self):
print("Swim Faster")

class Penguin(Bird):

def __init__(self):
# memanggil super func
super().__init__()
print("Penguin Initialization")

def siapaYa(self):
print("Penguin")

def run(self):
print("Run Faster")

ping = Penguin()
ping.siapaYa()
ping.swim()
ping.run()
18 changes: 18 additions & 0 deletions darmawanabi/oop_overloading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class A:

def __init__(self, a):
self.a = a

def add(self, b):
return self.a + b.a


obj1 = A(1)
obj2 = A(2)
obj3 = A("hemmmm")
obj4 = A("apasii")

print(obj1 + obj2)
print(obj3 + obj4)

# masih error
20 changes: 20 additions & 0 deletions darmawanabi/oop_polymorphism.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Parrot:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you must implement fly() method in Parrot class too.


def __init__(self):
print("Parrot can fly")

class Penguin:

def fly(self):
print("Penguin can't fly")

def flyingTest(bird):
bird.fly()

blu = Parrot()
# peggy = Penguin()

flyingTest(blu)
# flyingTest(peggy)

# masih error