class Hero:
# class variable
jumlah = 0
def __init__(self, inputName, inputHealt, inputPower, inputArmor):
# instance variable
self.name = inputName
self.healt = inputHealt
self.power = inputPower
self.armor = inputArmor
Hero.jumlah += 1
# method tanpa return
def siapa (self):
print ("Namaku adalah "+ self.name)
# method dengan argumen
def healtUp (self,up):
self.healt += up
# method dengan return
def getHealt (self):
return self.healt
hero1 = Hero ("sniper", 100, 5, 5)
hero2 = Hero ("sword", 130, 7, 2)
hero1.siapa()
hero1.healtUp(10)
print (hero1.getHealt())
Tidak ada komentar:
Posting Komentar