面向对象简单解释

来源:互联网 发布:淘宝代收点怎么设置 编辑:程序博客网 时间:2024/05/27 19:27

继承

{1,2,3}

{1,2,3,4,5}

class foo(object):    def __init__(self, arg)        self.a = 100;    def doAction(self, arg1, arg2)        self.b = arg1        self.c = arg2class child(foo):    def __init__(self, arg)        super(self,child).__init__(self, arg)        self.doAciton(self,1,2)        pass_a = child(1);print _a.aoverwrite

多态

a->run,b->run,c->run,for(int i = 0;  i < size; i++)    v[i]->run();

封装

public:    int a;private:    int b;

抽象

class foo{    public:        interface void a() = 0;    public run()    {        1        2        3        sgfgfsdg = a();        1        2        3    }}class method{    public void foo(interger a, interger b, interger...mmmm)    {    }}method a  = new method();a.foo(1,2,3);a.foo(1,2,3,4);a.foo(1,2,3,4,5);def foo(a, *b)    passfoo(1, 1,2,3);def foo2foo *b  = new foo();b->run();class child : public foo{}

类的属性&实例的属性

b = new foo(1,2);
c = new foo(3,4)

class foo()    a = 0;    def __init__(self, x, y)        self.c = x        seld.d = y        self.level = xxxx;        self.curExp = aaa;        #self.isUsed = true;        print x,y