Amazon.com Widgets Program 8.8
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 18, 2013, 03:11:14 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Program Examples
| | |-+  Chapter 8
| | | |-+  Program 8.8
Pages: [1]   Go Down
Print
Author Topic: Program 8.8  (Read 1149 times)
esc
Global Moderator
Full Member
*****
Posts: 230






« on: February 26, 2009, 02:19:47 AM »

Program 8.8
Code: (Objective-C)
// Extension of instance variables

#import <Foundation/Foundation.h>

// ClassA declaration and definition

@interface ClassA : NSObject
{
int x;
}

-(void) initVar;
@end

@implementation ClassA
-(void) initVar
{
x = 100;
}
@end

// ClassB declaration and definition

@interface ClassB : ClassA
{
int y;
}
-(void) initVar;
-(void) printVar;
@end

@implementation ClassB
-(void) initVar
{
x = 200;
y = 300;
}

-(void) printVar
{
NSLog (@"x = %i", x);
NSLog (@"y = %i", y);
}
@end


int main (int argc, char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    ClassB *b = [[ClassB alloc] init];

[b initVar];   // uses overriding method in ClassB
[b printVar];  // reveal values of x and y;

[b release];
    [pool drain];
    return 0;
}
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.