[파이썬] OOP TEST

jychae·2022년 11월 1일
0

파이썬

목록 보기
1/8

ooptest.py

class Animal:
    def __init__(self):
        self.age = 0
    def getOlder(self):
        self.age+=1
        
class Human(Animal):
    def __init__(self):
        super().__init__()
        self.skill_lang = 1
    def momstouch(self,stroke):
        self.skill_lang += stroke
        
hum = Human()
print(hum.skill_lang)
print(hum.age)
hum.getOlder()
hum.momstouch(5)
print(hum.skill_lang)
print(hum.age)
        
        

ooptest2.py

class Creature:
    def __init__(self):
        print("생성자")
        
    def __del__(self): # 죽여주는애
        print("소멸자")
        
    def __str__(self): #자바의 toString역할 잘 안씀
        return "babo"
        
if __name__ == '__main__': # 자바의 메인메서드 같은 것  여기서 안하면 중복
    cre = Creature()      

ooptest3.py

from day03.ooptest2 import Creature

cre = Creature()

ooptest4.py

class LeeJY:
    def __init__(self):
        self.money = 10
        
    def sllmn(self):
        self.money += 1

class Ellon:
    def __init__(self):
        self.coin = 1
        
    def bbeong(self):
        self.coin *= 2
        
class Jinho(LeeJY,Ellon): #다중상속이 됨 파이썬은!
    def __init__(self):
        LeeJY.__init__(self) #생성자만든것
        Ellon.__init__(self) #생성자만든것
        
jin = Jinho()
print(jin.money)
print(jin.coin) 
jin.sllmn()
jin.bbeong()
print(jin.money)
print(jin.coin) 

profile
안녕하세요! 초보개발자 공부 시작!

0개의 댓글