Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed to clear a minute concept about inheritance in general and its implementation in OOP. Please see
    primarykey
    data
    text
    <p>I am curious as to how the concept of "inheritance" takes place in the world of object oriented programming. Let me explain my dilemma (I came across this dilemma while studying Java but I hope that my question is generic in nature) :</p> <p>Suppose there is a class A and a class B. Class A <strong>"inherits"</strong> Class B. What does this actually mean? Does the compiler make a <strong>"new"</strong> class, which is <em>THEN</em> instantiated into an object which contains the elements of both the classes A and B behind the scenes? If that's the case, then how are the access restrictions implemented according to the access specifiers?</p> <p>For a moment, I wondered if it happens in the following manner :</p> <p>An object of class A is created and then an object of class B is created. Java then somehow "link" the members of A to the members of B and make it appear as if they belonged to the same class and it does that according to the access specifiers. </p> <p>But then, it occurred to me that there is a fault with this theory. Suppose two different classes, B and C are inheriting class A. Then, if we are going to make objects of class B and class C, then they'll have their OWN copies of the elements of class A. So this theory fails too.</p> <p>I was just trying to explain the confusion about inheritance that I have in my mind. It's giving me headache. Please help.</p> <p>EDIT : This is a link to a discussion related to my question which i found on this site. </p> <p><a href="https://stackoverflow.com/questions/4716040/does-subclasses-inherit-private-fields">Do subclasses inherit private fields?</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload