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

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 » Fri Feb 22, 2013 6:51 pm

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: 8543
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Fri Feb 22, 2013 7:47 pm

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 » Mon Feb 25, 2013 11:39 am

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: 8543
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Mon Feb 25, 2013 1:52 pm

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: 8
Joined: Mon Apr 01, 2013 8:38 am
Contact:

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

Post by webber » Tue Apr 02, 2013 6:40 am

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: 8543
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Tue Apr 02, 2013 1:14 pm

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: 8
Joined: Mon Apr 01, 2013 8:38 am
Contact:

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

Post by webber » Sat Apr 06, 2013 2:45 am

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: 74
Joined: Sun Jun 30, 2013 10:04 pm
Contact:

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

Post by ewebxml » Fri Jul 05, 2013 12:37 am

/* 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: 8543
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Fri Jul 05, 2013 6:02 am

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 » Tue May 13, 2014 2:33 pm

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

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

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

Post by dvc1190 » Fri Sep 16, 2016 5:58 pm

"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: 8543
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Fri Sep 16, 2016 11:16 pm

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: 14
Joined: Tue Feb 25, 2014 3:14 am
Contact:

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

Post by dvc1190 » Tue Oct 04, 2016 7:48 pm

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: 8543
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Tue Oct 04, 2016 8:53 pm

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 » Tue Dec 05, 2017 4:08 am

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: 8543
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Tue Dec 05, 2017 4:20 am

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest