Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 387815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:42:32+00:00 2026-05-12T15:42:32+00:00

I noticed whilst playing around today that both the objects below when sent init

  • 0

I noticed whilst playing around today that both the objects below when sent “init” print the same message “_init: TireSnow” to the console. Can anyone shed any light on why this is happening?

// INTERFACE
@interface TireBasic : NSObject {
}
@end

@interface TireSnow : TireBasic {
}
@end
// IMPLEMENT
@implementation TireBasic
- (id) init {
    self = [super init];
    if(self) {
        NSLog(@"TB_init: %@", NSStringFromClass([self class]));
    }
    return self;
}
- (NSString *) description {
return @"This is a BASIC TIRE.";
}
@end

@implementation TireSnow
- (id) init {
    self = [super init];
    if(self) {
        NSLog(@"TS_init: %@", NSStringFromClass([self class]));
    }
    return self;
}
- (NSString *) description {
return @"This is a SNOW TIRE.";
}

@end

EDIT2 – Added all of main()

#import <Foundation/Foundation.h>
#import "CarParts.h"

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

    int tireCount;
    CarClass *newCar_001;
    EngineClass *newEngine_001;
    TireBasic *newTire_BASIC;
    TireSnow  *newTire_SNOW;

    // Setup
    NSLog(@"COMPOSITION Start");
    newCar_001 = [[CarClass alloc] init];

    // Engine
    newEngine_001 = [[EngineClass alloc] init];
    [newCar_001 setEngine: newEngine_001];

    // TIRES (BASIC)
    for(tireCount=0; tireCount<2; tireCount++) {
        newTire_BASIC = [[TireBasic alloc] init];
        [newCar_001 setTire:newTire_BASIC];
        [newTire_BASIC release];
    }
    // TIRES (SNOW)
    for(tireCount=0; tireCount<2; tireCount++) {
        newTire_SNOW = [[TireSnow alloc] init];
        [newCar_001 setTire:newTire_SNOW];
        [newTire_SNOW release];
    }
    // Display
    [newCar_001 printCar];

    // Clean up
    [newCar_001 release];
    [newEngine_001 release];
    [pool drain];
    return 0;
}

OUTPUT

> COMPOSITION Start
> _init: CarClass
> _init: EngineClass
> TB_init: TireBasic
> TB_init: TireBasic
> TB_init: TireSnow *****
> TS_init: TireSnow
> TB_init: TireSnow *****
> TS_init: TireSnow
>  
> This is a BASIC TIRE.
> This is a BASIC TIRE.
> This is a SNOW TIRE.
> This is a SNOW TIRE.
> 
> _deal: CarClass
> TB_deal: TireBasic
> TB_deal: TireBasic
> TS_deal: TireSnow
> TB_deal: TireSnow ******
> TS_deal: TireSnow
> TB_deal: TireSnow ******
> _deal: EngineClass

The line with stars are coming from the TireSnow [super init] and [super dealloc], it seems to be [self class] that is returning “TireSnow” each time, can anyone explain why?

many thanks

gary

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T15:42:33+00:00Added an answer on May 12, 2026 at 3:42 pm
    > TS_deal: TireSnow
    > TB_deal: TireSnow
    

    You’re asking why TireSnow is printed twice?

    First [TireBasic init] runs, then [TireSnow init]. In both cases they print the class name, and in both cases the class name is TireSnow.

    In other words, [self class] will always return the same object, regardless of which method it’s executing in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 231k
  • Answers 231k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use the following function like this: Image('/path/to/original.image', '1/1', '150*', './thumb.jpg');… May 13, 2026 at 2:13 am
  • Editorial Team
    Editorial Team added an answer Check you database schema to see if the field (referenced… May 13, 2026 at 2:13 am
  • Editorial Team
    Editorial Team added an answer I figured out the problem - there was a session… May 13, 2026 at 2:13 am

Related Questions

I'm using Tomcat 6.2 and Spring MVC 2.5. I've noticed that, whilst a user
Whilst working on a UI update for a client, I noticed the dates associated
We have a SQL 2005 database server which uses high safety (synchronous, no automatic
I'm currently moving a website to a new server, whilst doing so i've noticed

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.