iOS基础知识巩固
黄舟
黄舟 2017-04-17 17:49:32
0
1
418

1.有人知道,类方法,也称静态方法,指的是用static关键字修饰的方法。此方法属类本身的方法,不属于类的某一个实例(对象)。类方法中不可直接使用实例变量。其调用方式有三种:可直接调用、类名.方法名、对象名.方法名。怎么理解这里的调用方式中,调用类名,对象名这两种,我实在是看不理解

2.我这里自己定义一个汽车类,汽车是一个类,洗车,修车是实例方法,
然后一家制造厂制造了多少款汽车,要实现这个方法,
结果这个方法要定义成类方法,
这里我也是不理解,

3.在实例方法里,根据继承原理发送消息给self和super其实都是发送给self,这里我也是不理解,

4.在类方法里面self是其他的类的类方法,在类方法中给self发送消息只能发类方法self是类super也是,这里我也是不理解,

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
左手右手慢动作
  1. Generally speaking, you only need to remember that classes call class methods and instances call instance methods

  2. Car washing and repairing are things that can only be done when there is already an instance of the car, so the instance method is called;
    Building a car is a constructor method, which needs to be called by a class to generate an instance object, so it is a class method ;

  3. In the instance method, self is the instance object itself, and what is called is naturally its own instance method; and when super sends a message, it is actually self that calls the method of the parent class;

  4. "In a class method, self is a class method of other classes"?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!