About Question enthuware.ocajp.i.v8.2.1147 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
babur12
Posts: 1
Joined: Thu Jan 12, 2017 2:42 pm
Contact:

About Question enthuware.ocajp.i.v8.2.1147 :

Post by babur12 »

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?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1147 :

Post by admin »

Instance initializers are not inherited either.
If you like our products and services, please help us by posting your review here.

Rinkesh
Posts: 35
Joined: Sat Nov 25, 2017 4:13 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1147 :

Post by Rinkesh »

Sir can you give me a example of static initializer?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1147 :

Post by admin »

If you like our products and services, please help us by posting your review here.

Hiar85
Posts: 2
Joined: Wed Jan 03, 2018 9:46 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1147 :

Post by Hiar85 »

"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

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1147 :

Post by admin »

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.
If you like our products and services, please help us by posting your review here.

Rick84
Posts: 12
Joined: Tue Mar 06, 2018 9:54 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1147 :

Post by Rick84 »

Objects of class B will always have a member variable named i.
Note that 'i' is not public or protected. So it will be inherited only if both the classes are in same package.
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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1147 :

Post by admin »

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.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 58 guests