Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class instance methods? object methods?

According to Wikipedia:

Class methods are methods that are called on a class (compare this to class instance methods, or object methods).

Could you guys please clarify object methods to me? And Class instance methods are Instance methods if i'm correct?

like image 831
Michael C Avatar asked Feb 22 '23 10:02

Michael C


2 Answers

Yes, Class instance methods = Object methods because Object == Class instance. An object is an instance of a class. From wikipedia:

In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects.

like image 131
Tudor Avatar answered Mar 05 '23 07:03

Tudor


In objective C class method is used by just class name, you dont need to create a instance of class to access these methods.. But for object methods you need to create an instance of the class which means creating a object of class.. In objective C +/- identifiers are used for it;

@interface AClass: NSObject

+ (void)classMethod;
- (void)instanceMethod;

@end

[AClass classMethod];

AClass *object = [[AClass alloc] init];
[object instanceMethod];
like image 21
Fatih Donmez Avatar answered Mar 05 '23 05:03

Fatih Donmez