1

Which class is Abstract class in Objective-C, I have read some doc where NSObject is Abstract class, but we can create instance of NSObject, then how it is follow the abstract class rule.

NSObject *obj = [[NSObject alloc] init];    
NSLog(@"description = %@",[obj description]);    
NSLog(@"class name = %@",[obj class]); 

Please advice.

And also I heard another one Abstract Class in Objective-C, what is the name of the class?

Monolo
  • 18,205
  • 17
  • 69
  • 103

2 Answers2

3

Objective-C has no compile time restraint against instantiating abstract classes. See Creating an abstract class in Objective-C

Community
  • 1
  • 1
Cody Poll
  • 7,690
  • 3
  • 27
  • 22
0

In Objective-C there is no language level concept of an abstract class. You have to read the documentation for a class to find out if it should be treated as an abstract class. There are a few such classes in Cocoa, e.g. NSObject, NSProxy and NSOperation. It's more common for behaviour to be defined in protocols rather than in abstract classes.

The Cocoa framework contains to root classes (i.e. class which do not have superclasses). NSObject is one root class and NSProxy is the other. NSProxy does not implement an init method which means an exception is raised when you attempt to create an instance.

Benedict Cohen
  • 11,912
  • 7
  • 55
  • 67