Skip to content

Instantly share code, notes, and snippets.

@solanoize
Last active May 3, 2024 10:40
Show Gist options
  • Select an option

  • Save solanoize/7137b4d09ad0fe15ff377774fa706ab1 to your computer and use it in GitHub Desktop.

Select an option

Save solanoize/7137b4d09ad0fe15ff377774fa706ab1 to your computer and use it in GitHub Desktop.
class Mobil:
def __init__(self, merk, tahun):
self.merk = merk
self.tahun = tahun
def run(self):
return f"Mobil {self.merk} berjalan..."
class Honda(Mobil):
def __init__(self, merk, tahun, mesin):
super().__init__(merk, tahun)
self.mesin = mesin
# Cara 1 sebelum pewarisan
# -------------------------
# mobil = Mobil("Honda", "2001")
# mobil.merk = "Oke"
# print(mobil.run())
# Cara 2 setelah pewarisan
# ------------------------
brilio = Honda("Honda Brilio", 2011, "VVTI")
brilio.merk = "Hondu Brother"
print(brilio.run())
class Weapon:
def __init__(self, name, damage):
self.name = name
self.damage = damage
class Hero:
def __init__(self, weapon, name):
self.weapon = weapon
self.name = name
def attack(self):
return f"{self.name} attack with {self.weapon.name}"
stick = Weapon("Stick Sihir", 20)
vexana = Hero(stick, "Vexana")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment