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

  • SEARCH
  • Home
  • 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 8233855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:16:15+00:00 2026-06-07T18:16:15+00:00

As a C#/Java Programmer I’m having a hard time getting the following problem solved:

  • 0

As a C#/Java Programmer I’m having a hard time getting the following problem solved:

There is a base class “B”. In its init Method it calls a method “SetupStuff”.
For the base class this method is just empty.

Then there is a derived class “D” that inherits from “B”.
D implements the method “SetupStuff”, too (and actually does something there).

The problem is: When I create an object of D, its “SetupStuff” is never called. The init method of B is called, then the empty “SetupStuff” of is called.

What would I need to do to make the derived class’s method being called?

  • 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-06-07T18:16:17+00:00Added an answer on June 7, 2026 at 6:16 pm

    If you are trying to invoke an override from inside your initializer, it is not going to work. The reason for it is easy to understand: since the override belongs to a subclass, and because the superclass instance initialization needs to be complete before the subclass initialization can start, calling a derived method would have violated the rules that by the time a “regular” method is called the initialization of the instance has completed. Generally, calling virtuals from Java or C# constructors is not a good idea, for the same exact reason. In C++, calling virtuals from a constructor redirects to the implementation in the cosntructor’s own class (i.e. the same thing that you observe in Objective C).

    Unlike C# and Java where overriding static methods is not allowed, Objective C lets you provide class-specific implementations of class methods. You can use this mechanism to achieve what you are trying to do: define a class method in the derived class, and call it from the base class, like this:

    @interface TT : NSObject
    -(id)init;
    @end
    
    @interface Test1 : TT
    +(void)doit;
    @end
    
    @interface Test2 : TT
    +(void)doit;
    @end
    
    @implementation Test1
    +(void) doit {
        NSLog(@"Test1");
    }
    @end
    
    @implementation Test2
    +(void) doit {
        NSLog(@"Test2");
    }
    @end
    
    @implementation TT
    -(id) init {
        if (self=[super init]) {
            // The "magic" is in the following line:
            [self->isa doit];
        }
        return self;
    }
    @end
    

    When you call

    [[Test1 alloc] init];
    [[Test2 alloc] init];
    

    you see

    Test1
    Test2
    

    in the log.

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

Sidebar

Related Questions

I'm mainly a java programmer and I'm getting started with C++. I wonder if
First time Java programmer. I'm wondering what my options are for loading XML on
I am a new Java programmer. The following is my code: public static void
I am a former java programmer, and I am having some troubles managing the
Being a long-time Java programmer and in recent years a Haskell addict, I am
I am a Java programmer trying to transition to C# and I'm hoping there's
I am a Java programmer, learning Objective-C and I have a problem with implementation
I'm a relatively new Java programmer and I'm having difficuly removing more than one
I've recently started learning Python (long time Java programmer here) and currently in the
I'm originally a Java programmer who now works with Objective-C. I'd like to create

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.