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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:23:34+00:00 2026-05-15T07:23:34+00:00

// A : Parent @implementation A -(id) init { // change self here then

  • 0
// A : Parent
@implementation A
-(id) init
{
    // change self here then return it
}
@end A

A *a = [[A alloc] init];

a. Just wondering, if self is a local variable or global? If it’s local then what is the point of self = [super init] in init? I can successfully define some local variable and use like this, why would I need to assign it to self.

-(id) init
{
    id tmp = [super init];
    if(tmp != nil) {
        //do stuff
    }
    return tmp;
}

b. If [super init] returns some other object instance and I have to overwrite self then I will not be able to access A’s methods any more, since it will be completely new object? Am I right?

c. super and self pointing to the same memory and the major difference between them is method lookup order. Am I right?

sorry, don’t have Mac to try, learning theory as for now…

  • 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-15T07:23:34+00:00Added an answer on May 15, 2026 at 7:23 am

    Dreamlax’s answer is correct… but, clarification may be helpful.

    a. Just wondering, if self is a local
    variable or global? If it’s local then
    what is the point of self = [super
    init] in init? I can successfully
    define some local variable and use
    like this, why would I need to assign
    it to self.

    self is not a local variable. It is an argument to the method call. The first argument, in fact. The second argument is _cmd, the name of the selector of the method being executed.

    What is special about self is that self is used by the compiler to access instance variables. That is, if you say self = [super init] and the superclass’s init happens to return something different, any further instance variable accesses will still be correct.

    b. If [super init] returns some other
    object instance and I have to
    overwrite self then I will not be able
    to access A’s methods any more, since
    it will be completely new object? Am I
    right?

    If super’s init returns an instance of something that is incompatible with A, then something has gone horribly awry in the design of the superclass. Keep in mind that Objective-C is fully dynamic. Thus, there is no reason that whatever is returned by super’s init actually needs to be an instance of A, but it better had damned well act like an A. Now, it could be a completely new instance of a subclass of A and, thus, all of the methods of A will work just fine.

    Reading between the lines; remember that Objective-C is fully dynamic. There is no such thing as static method dispatch. The class of an object could change at any time and any random method call will still work as long as the new class responds to the method. Not that this actually happens at runtime, just that it could.

    c. super and self pointing to the same
    memory and the major difference
    between them is method lookup order.
    Am I right?

    Now, this is the fun question. super doesn’t really point to anything. For all intents and purposes, super can be treated as the one bit of magic in this. That is, when the compiler sees super as the target of a method call, it compiles it as a slightly different call site that calls through to one of the variants of objc_msgSendSuper() which — as name implies — effectively “searches” for the method’s implementation starting in the parent class of the class within which the call was compiled.

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

Sidebar

Related Questions

My implementation of QTabWidget is not detecting its tabCloseRequested() and currentChanged() signals. TileSheetManager::TileSheetManager(QWidget *parent)
I'm looking for a Generic DAO implementation in Hibernate that includes parent/child relationship management
Class parent { protected void myMethod() { if(someCodition) { //return this as well as
I want to know if this is possible alloc child class from parent and
This is my implementation of A* in Python class Node: def __init__(self, (x, y),
In the header, I declare my NSString *name; Variable. Then I make it a
Say we have parent class ParentViewController.h @interface ParentViewController .... @end ParentViewController.m @interface ParentViewController() -
I want a pure virtual parent class to call a child implementation of a
if I want to add something to the implementation of public static function createPopUp(parent:DisplayObject,
The following XML implementation seems to work fine: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent

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.