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 7447557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:38:51+00:00 2026-05-29T12:38:51+00:00

If I have a super class with a convenience constructor as follows (using ARC):

  • 0

If I have a super class with a convenience constructor as follows (using ARC):

+(id)classA {
    ClassA *foo = [[ClassA alloc] init];

    return foo;
}

If I then subclass ClassA, with a class named ClassB, and I want to override the convenience constructor, is the following correct:

+(id)classB {
    ClassB *foo = [ClassA classA];

    return foo;
}

(Assume that I cannot call alloc and init on ClassB).

Thanks!

  • 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-29T12:38:55+00:00Added an answer on May 29, 2026 at 12:38 pm

    No, that is not correct, since that allocates, inits and returns a ClassA, not a ClassB. The only way to do this is not to use ClassA explicitly:

    + (id) classA
    {
        return [[self alloc] init];
    }
    

    Of course, you could also use old-fashioned new for this:

    ClassB *myB = [ClassB new];
    

    FWIW, assuming I would want to do more than just allocate and init, and my class is named Gadget, then I would do something like:

    + (id) gadgetWithNumber: (int) num
    {
        return [[self alloc] initWithNumber: num];
        // or without ARC:
        // return [[[self alloc] initWithNumber: num] autorelease];
    }
    

    Of course that assumes that there is an initWithNumber: method in my class.

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

Sidebar

Related Questions

If subclass in objective-c wants to override a super class's method, does it have
I have a super-class named ClassA and two sub-classes Class1 and Class2. I have
I have done a few projects lately using a Database Object super class which
I have a NSViewController subclass with a convenience method to return the window controller
Previously, I generate the programme using code, and I have a super class that
Let's say I have a table that represents a super class, students . And
I have a super class like this: class Parent { public: virtual void Function(int
I have a generic class that is also a mapped super class that has
I have a super class 'Node' and several sub classes e.g. 'SubNode1', 'SubNode2' etc.
I have a super class: public class SuperClass { public void dosomething() { firstMethod();

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.