Help, please, with theory. It is possible and practical examples.

Parse this and super . What I understood: this is a link to itself. That is, I can not access from another class through this . If I register in another class, I will receive another link to the class, but not another, but myself again.

And super is getting the ancestor's methods, but only the last, not the ancestor of its ancestor. Is it so? Or have I misunderstood somewhere?

    3 answers 3

    super is an instruction to the compiler to call in a non-virtual way to the parent method on the current object ( this ). That is why it cannot be saved to a variable.

      this is you. super is your mother. If you say this and super you mean yourself and your mother. If I say this and super - I point to myself and my mother, and not to you or your mother (this is if my and your mother are not the same person).

      • ten
        o_O nothing to add - katso
      • 3
        The best definition for the concept. But at the interview so to speak, of course, is not necessary))) - pavel163
      • 3
        @ pavel163 but what, said super to the interviewer - this is your mother and they will immediately hire you. - Alexey Shimansky
      • four
        @katso, you can also add "you are your mother" (this is Java and OOP, the heir is the parent). Awful and wildly holey abstraction. - PashaPash
      • 3
        @Qwertiy in terms of classes - yes. in terms of instances, no. and then someone comes in and asks something like "how can I get a link to this nurse " ru.stackoverflow.com/questions/560889 . - PashaPash

      In the next response from @Xoxole, community representatives found flaws. In particular, mother and child are different objects, and this and super are one. I will try to fix them.

      this is you now, that is, a copy of an adult person who can read and write. super - this is all you have left of yourself in infancy, who knows how to eat from a bottle. If you say this and super you mean yourself and yourself as a child. If I say this and super - I point to myself and myself in infancy, and not to you now or in childhood. When you and I became adults, we redefined the ability to eat from a bottle to the ability to eat from a plate with a fork. But we can still eat from the bottle (we can call the super methods on our own), but we will not show it to anyone - if we are offered lunch for others, we will agree only with a plate and fork.