About Question enthuware.ocajp.i.v7.2.1003 :

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

Moderator: admin

Post Reply
satar
Posts: 10
Joined: Tue Feb 12, 2013 9:12 pm
Contact:

About Question enthuware.ocajp.i.v7.2.1003 :

Post by satar »

Can I have a little more interpretation of what is meant by the statement "The use of inheritance is not justified here because a TwoWheeler is not really a FourWheeler". I must not be reading between the lines on this statement.

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

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by admin »

There is nothing much to interpret here. Do you think a two wheeler such as a motorcycle is a four wheeler such as a car? In a way like a car is an automobile?

In other words, if you model a Car, you could possibly model it as extending from Automobile because a Care really is an Automobile. But if you model a TwoWheeler, would you extend it from FourWheeler? If you do, it would not be justified.

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

satar
Posts: 10
Joined: Tue Feb 12, 2013 9:12 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by satar »

The way this source code is written, TwoWheeler is a subclass of FourWheeler; therefore, it inherits from it whether it makes sense or not. There are many questions in the exam that I would never write that way but it is more a test of knowing the language itself right? Maybe I am still not following but (correct me if I am wrong) regardless of whether in reality a TwoWheeler is not really a FourWheeler, based on the pure essences of the source code example in this question, the class TwoWheeler, does inherit from FourWheeler.

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

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by admin »

Yes, that is why the question asks whether the use of inheritance is justified i.e. whether is makes sense here. The question is not asking you whether inheritance is used, because it is clear that it is used here, but whether the use of inheritance is justified.


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

webber
Posts: 18
Joined: Mon Apr 01, 2013 8:38 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by webber »

public interface Automobile { String describe(); }

Therefore Automobile in an interface.

Can we really writte: "An instance of TwoWheeler is a valid instance of Automobile"

It seems a little strange that an instance of an interface :?: :shock:

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

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by admin »

webber wrote:public interface Automobile { String describe(); }

Therefore Automobile in an interface.

Can we really writte: "An instance of TwoWheeler is a valid instance of Automobile"
Yes, you can write that and it is correct to write that.
It seems a little strange that an instance of an interface :?: :shock:
It is true that it feels strange. That is why some people make a distinction between is-a and is-like-a, where is-a is used when you extend a class and is-like-a is used when you implement an interface.
So for example if you have an interface named Moveable, which is implemented by class Car, you would say, Car is-like-a Moveable instead of Car is-a Moveable.

For the purpose of the exam, however, there is no difference between the two. is-a is the term that should be used for the exam. There is no is-like-a.

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

webber
Posts: 18
Joined: Mon Apr 01, 2013 8:38 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by webber »

Thanks.

Of course, I am easily agree with the sentence: "Car is-a Moveable"

But it would be strange to read "Car is a valid instance of Moveable".

It seems me a corrector could decide: "Bad proposition, there is never instance of interface, you have lost a point... try again..."

It's very ambiguous.

I hope there will not be too much questions with "valid instance of interface", or "valid instance of abstract class" in my exam. I would not know what they want me to answer !

ewebxml
Posts: 78
Joined: Sun Jun 30, 2013 10:04 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by ewebxml »

/* The code does not compile unless you remove the "public" access modifier from the interface. */
// Does not compile
public interface Automobile { String describe(); } // the public type automobile must be defined in its own file
class FourWheeler implements Automobile{
String name;
public String describe(){ return " 4 Wheeler " + name; }
}
class TwoWheeler extends FourWheeler{
String name;
public String describe(){ return " 2 Wheeler " + name; }
}

// -----------------------------------------------------------
// Compiles
interface Automobile { String describe(); }
class FourWheeler implements Automobile{
String name;
public String describe(){ return " 4 Wheeler " + name; }
}
class TwoWheeler extends FourWheeler{
String name;
public String describe(){ return " 2 Wheeler " + name; }
}
-----------------------------------------------------------
Please confirm.
That is why I selected option e)

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

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by admin »

The question does not specify the name of the file. So you have to assume that it is valid. Anything that is not clearly specified should be assumed to not affect the answer.

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

JeramieH
Posts: 22
Joined: Wed Jan 08, 2014 11:24 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by JeramieH »

It's like a version of the classic Circle-ellipse problem

dvc1190
Posts: 15
Joined: Tue Feb 25, 2014 3:14 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by dvc1190 »

"The use of inheritance is not justified here because a TwoWheeler is not really a FourWheeler".

That seems like a subjective statement. There are definitely 2-wheel cars that inherit many aspects of a 4-wheeled automobile, except the number of wheels. I would say the Ford Gyron https://en.wikipedia.org/wiki/Ford_Gyronis is-a 4-wheeled car, but with 2-wheels.

Are there subjective questions like this on the test? If not, then please remove option 3 from this question. What concept is it even trying to teach?

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

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by admin »

Sharing features doesn't mean there is an is-a relationship. The argument that you've made can be made even for Plant and Animal? Is an Animal a Plant? Both are living things. But if you extend Animal class from Plant, would you call it justified?


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

dvc1190
Posts: 15
Joined: Tue Feb 25, 2014 3:14 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by dvc1190 »

admin wrote:Sharing features doesn't mean there is an is-a relationship. The argument that you've made can be made even for Plant and Animal? Is an Animal a Plant? Both are living things. But if you extend Animal class from Plant, would you call it justified?


HTH,
Paul.
I think you're missing the point of why I bought this software. I want preparation for questions that will appear on the exam. Are subjective questions like this on there or not? To what degree will answers be open to interpretation?

If something like this will not appear, then please remove it. It's a waste of my time.

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

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by admin »

On this particular topic, yes. You may find some questions that are subjective. That is why we have included it.

You should go with the simple and straight forward interpretation. If you have to conjure up some weird situation to justify a particular option, then that option is most probably a wrong option.

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

raj_dp
Posts: 16
Joined: Sun Jun 12, 2016 7:43 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by raj_dp »

Hi in this example, in the class FourWheeler there is an instance variable 'name'.
When TwoWheeler extends FourWheeler, this variable will also get inherited to class TwoWheeler.
But in class TwoWheeler another instance variable 'name' is declared.
So with an instance of TwoWheeler when we call variable 'name' which one will be called?
Or the variable in TwoWheeler is suppressing the inherited variable 'name' from the superclass FourWheeler.

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

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by admin »

In variable declared in a subclass always hides the variable of the same name declared in the superclass. Therefore, if you try to access that variable in the subclass using "this" (whether explicitly or implicitly), it is the subclass's variable that will be used.
See this trail: https://docs.oracle.com/javase/tutorial ... ables.html
If you like our products and services, please help us by posting your review here.

cronicmanga
Posts: 2
Joined: Fri Mar 04, 2022 2:36 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by cronicmanga »

Honestly I cannot see how this questions is even subjective. A two wheeler and a four wheeler are separate by definition, directly opposing. You cannot have both 2 AND 4 wheels. You might argue that a 4 wheeler does indeed have 2 wheels by having 4, but even then the reference is clearly referring to standard dialect people use when referring to vehicles.

If you struggle to picture the relationship it might be easier to think of it another step below. A 4 wheeler can be split into Cars and trucks. Both have 4 wheels but in addition to that a truck has a bed. You get more specific going down the inheritance.

agupta108
Posts: 4
Joined: Sat Jan 20, 2024 9:26 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by agupta108 »

"The use of inheritance in this code is not justifiable, since conceptually, a TwoWheeler is-not-a FourWheeler." -> this explaination is not correct. The compiler doesn't knows anything about the conceptual real-world situations. Option C: " The use of inheritance is not justified here because a TwoWheeler is not really a FourWheeler in the real world that the code is trying to model." -> SHOULD BE INCORRECT

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

Re: About Question enthuware.ocajp.i.v7.2.1003 :

Post by admin »

The option doesn't say legal. It says justifiable. It has nothing to do with compilation. The explanation is correct.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests