Last active
May 3, 2024 10:40
-
-
Save solanoize/7137b4d09ad0fe15ff377774fa706ab1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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()) |
This file contains hidden or 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 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