ooptest01.py

class Vehicle:
    def __init__(self):
        print("생성자")
        self.cnt_wheel = 2    
    def addWheel(self):
        self.cnt_wheel += 2
    def __del__(self):    
        print("소멸자") 

class Car(Vehicle):
    def __init__(self):
        self.amount_fuel = 0
        super().__init__()
    def mantank(self):
        self.amount_fuel = 100
    def onedollor(self):
        if self.amount_fuel >= 100:
            print("만땅이유")
            return 
        self.amount_fuel+=1
                  
c = Car()
print(c.cnt_wheel)
print(c.amount_fuel)
c.addWheel()
c.mantank()
c.onedollor()
print(c.cnt_wheel)
print(c.amount_fuel)

 

결과

생성자
2
0
만땅이유
4
100
소멸자

'파이썬' 카테고리의 다른 글

[파이썬] qtpy 전화기, 가위바위보  (0) 2023.02.24
[파이썬] 다중상속  (0) 2023.02.21
[파이썬] test(가위,바위,보)  (0) 2023.02.21
[파이썬] 함수(def)  (0) 2023.02.20
[파이썬] test  (0) 2023.02.20

+ Recent posts