About Question enthuware.ocajp.i.v8.2.1147 :
Moderator: admin
-
- Posts: 1
- Joined: Thu Jan 12, 2017 2:42 pm
- Contact:
About Question enthuware.ocajp.i.v8.2.1147 :
From this quote "Constructors and static initializers are not members and therefore are not inherited."
Since static initializers are not inherited and there is nothing said about instance initializers, does that mean instance initializers?
Since static initializers are not inherited and there is nothing said about instance initializers, does that mean instance initializers?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1147 :
Instance initializers are not inherited either.
If you like our products and services, please help us by posting your review here.
-
- Posts: 35
- Joined: Sat Nov 25, 2017 4:13 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1147 :
Sir can you give me a example of static initializer?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1147 :
If you like our products and services, please help us by posting your review here.
-
- Posts: 2
- Joined: Wed Jan 03, 2018 9:46 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1147 :
"Note that 'i' is not public or protected. So it will be inherited only if both the classes are in same package."
Imho this is not the reason that this answer is correct.
At runtime, when an actual object is created, the child object contains all the members of its parent class, even the private ones.
See:
https://stackoverflow.com/questions/471 ... ate-fields
Imho this is not the reason that this answer is correct.
At runtime, when an actual object is created, the child object contains all the members of its parent class, even the private ones.
See:
https://stackoverflow.com/questions/471 ... ate-fields
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1147 :
Inheritance is a technical term and has a specific meaning in Java language as defined by the Java Language Specification. private members are not inherited. A subclass cannot access the private members of the base class. Plain and simple. When you talk about the word "inheritance" in context of Java, this is the meaning you should refer to.
Now, from a memory perspective, obviously, when the JVM allocates space for an object of a subclass, that space is the sum of all the space required for members of the base class(es) and the space required for the members of the subclass. So yes, superclass fields are there in the subclass in some form but that is totally irrelevant from Java programming (and the certifcation exam) point of view.
Now, from a memory perspective, obviously, when the JVM allocates space for an object of a subclass, that space is the sum of all the space required for members of the base class(es) and the space required for the members of the subclass. So yes, superclass fields are there in the subclass in some form but that is totally irrelevant from Java programming (and the certifcation exam) point of view.
If you like our products and services, please help us by posting your review here.
-
- Posts: 12
- Joined: Tue Mar 06, 2018 9:54 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1147 :
Objects of class B will always have a member variable named i.
I think this question is confusing. As the explanation states, it won't always have a member variable i, but only if the classes are in the same package. I feel this question might be clearer if the member variables are defined public or protected.Note that 'i' is not public or protected. So it will be inherited only if both the classes are in same package.
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1147 :
As per the code that is given in the question, B will always have i. The explanation is merely reminding that if class B belongs to a different package, then it will not inherit i.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Google [Bot] and 58 guests