Python2.x_面向对象基础

 

class Car: #定义类
    price = 10000 #定义类属性
    def __init__(self, c): #定义构造函数
        self.__color = 'Red' #定义私有属性,私有属性在类外不能直接访问
        self.color = c #定义实例属性
    def __printColor(self): #定义私有方法
        print(self.__color)
    def printColor(self): #定义共有方法
        self.__printColor()
    def getPrice(): #定义静态方法
        return Car.price

car1 = Car("Red")
Car.price = 20000 #修改类属性
Car.name = 'QQ' #增加类属性
car1.color = "Yellow" #修改实例属性
posted @ 2015-07-05 17:30  yoleimei  阅读(93)  评论(0编辑  收藏  举报