While going through an Objective C programming book just now . I noticed this code
@interface Fraction: NSObject
{
int numerator;
int denominator;
}
-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
@end
Author does great job in explaining every thing in this book but there is no mention on whether this is same as just
@interface Fraction
{
int numerator;
int denominator;
}
-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
@end
reason I am asking this rather very simple question is that in JAVA every thing by default extends Object and you do not need to say that. Now of course they are two very different languages but it was a natural question that came to my mind.
No, the two examples are not the same.
@interface Fractioncreates a new root class that is not associated with theNSObjecthierarchy at all. As such, it won’t even respond to+alloc; you would have to implement your own allocation method. You almost never want to do that.