Page 1 of 2

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

Posted: Sun Mar 05, 2017 7:06 am
by actuaris
I thought that if you have:

class A (int a = 5;}
class B extends A {int b = 10;}
class C extends B {int c = 2;}

would count as inheriting mutiple states for any instance of class C (it inherits both A's and B's state). Can you explain why this reasoning is false?

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

Posted: Sun Mar 05, 2017 8:39 am
by admin
From OOP perspective, C inherits only the state of B.
class B includes the state of A. C doesn't directly inherit the state of A.
This is the view adopted by the official Java tutorial as well - https://docs.oracle.com/javase/tutorial ... tance.html

HTH,
Paul.

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

Posted: Sun Mar 05, 2017 9:23 am
by actuaris
Thanks, I'll remember it for the exam.

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

Posted: Tue Mar 07, 2017 2:30 pm
by lenalena
This question threw me off because the last option states:

"Multiple inheritance of type includes the ability to implement multiple interfaces and/or ability to extend from multiple classes"

I am not sure about "ability to extend from multiple classes" part of the answer choice... Wouldn't that apply to multiple inheritance of state, not type? Also, from the explanation, it says that a "class can extend only from one class at most". So even IF the above definition of multiple inheritance of type was correct (and I'm not sure why it is, but since it's marked as a correct answer, it must be) it would still be a wrong option, because Java doesn't allow an "ability to extend from multiple classes".

I am very confused (by a topic I thought I understood up to this question).

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

Posted: Tue Mar 07, 2017 10:16 pm
by admin
The statement is talking about multiple inheritance of type. Classes and interfaces are both types.

Java allows multiple inheritance of only interfaces. So in that sense Java does allow multiple inheritance of types.
A Class has a state as well. Java does not allow inheriting from multiple classes. That means Java does not allow multiple inheritance of state.

You should go through the link posted above for more detailed explanation.

HTH,
Paul.

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

Posted: Tue Mar 07, 2017 11:32 pm
by lenalena
admin wrote:The statement is talking about multiple inheritance of type. Classes and interfaces are both types.

Java allows multiple inheritance of only interfaces. So in that sense Java does allow multiple inheritance of types.
A Class has a state as well. Java does not allow inheriting from multiple classes. That means Java does not allow multiple inheritance of state.

You should go through the link posted above for more detailed explanation.

HTH,
Paul.
So you're saying that this particular option is talking about a theoretical (not specific to Java) "inheritance of type" which can include inheritance of multiple classes. Because if you're applying the concept of "inheritance of type" specifically to Java, then "in that sense" the option is not correct because it's talking about extending multiple classes.

I understand the theory behind multiple inheritance of type as it applies to Java, I read the link, and it's all clear. I just don't understand (still, even after your explanation) why the above option is correct. Don't the questions in the exam relate to the Java language specifically?

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

Posted: Tue Mar 07, 2017 11:35 pm
by admin
That is correct. There is no reference to Java in that statement. It is a statement just about multiple inheritance of type. The statement has "and/or". Not just "and". So even for Java, the statement is correct because of the "or" part.

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

Posted: Tue Mar 07, 2017 11:50 pm
by lenalena
admin wrote:That is correct. There is no reference to Java in that statement. It is a statement just about multiple inheritance of type. The statement has "and/or". Not just "and". So even for Java, the statement is correct because of the "or" part.
Thanks, the answer option is clear now.

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

Posted: Wed Mar 08, 2017 3:21 pm
by zserrbo
The question has also other two answer:
Multiple inheritance of state includes ability to inherit instance methods from multiple classes.
Multiple inheritance of state includes ability to inherit instance fields from multiple classes.

I don't understand. Why are they good answers?

From the explanation:
""State", on the other hand, is represented by instance fields and instance methods. "
"Thus, Java does not support multiple inheritance of state."

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

Posted: Wed Mar 08, 2017 9:39 pm
by admin
These options are correct because they are factually correct about the meaning of the term "Multiple inheritance of state".
It is true that Java does not support multiple inheritance of state but options don't claim so either. So there is nothing wrong with the options.

HTH,
Paul.

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

Posted: Sat Dec 29, 2018 6:51 pm
by crazymind
Hi, I wonder if the real test could contain any questions regarding the multiple inheritance?

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

Posted: Sat Dec 29, 2018 8:36 pm
by admin
Yes, questions on this concept are asked in the real exam.

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

Posted: Sat Dec 29, 2018 9:26 pm
by crazymind
Thanks.
Multiple inheritance of state includes ability to inherit instance fields from multiple classes.

I don't quite understand why is this one correct answers ? Isn't multiple inheritance including inherit instance fields and instance methods from multiple classes?

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

Posted: Sat Dec 29, 2018 10:19 pm
by admin
No, state means fields. Not methods. Please go through the discussion above.

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

Posted: Sun Aug 16, 2020 1:37 pm
by Chris1
maybe I was a bit quick here but I ruled out the correct answer
Multiple inheritance of type includes ability to implement multiple interfaces and/or ability to extend from multiple clases.
because there are no "clases" in java, only "classes" (as stated in the other answers). Good to know the exam does not ask questions on that ;)

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

Posted: Wed Jun 09, 2021 12:56 pm
by baichen7788
why is last option correct?
java only allows to extend from one class.
can you give an example on how java extends from multiple classes?

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

Posted: Wed Jun 09, 2021 1:05 pm
by admin
Please read the responses given above. Already answered exactly the same query above.

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

Posted: Wed Jun 09, 2021 1:15 pm
by baichen7788
I don't know which response above answered my question.

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

Posted: Wed Jun 09, 2021 2:49 pm
by admin
There is no reference to Java in the last option. It is just a statement about multiple inheritance of type, which includes extending from multiple interefaces (Java allows that) and / or multiple classes (Java doesn't allow that).

The statement has "and/or". Not just "and". So, even for Java, the statement is correct because of the "or" part.

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

Posted: Fri Jul 30, 2021 12:22 pm
by enthunoob
The last option is marked as correct but that's impossible as clases don't exist in OOP. Classes do though. :mrgreen:
Multiple inheritance of type includes ability to implement multiple interfaces and/or ability to extend from multiple clases.

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

Posted: Fri Jul 30, 2021 12:36 pm
by admin
Fixed.
thank you for your feedback!

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

Posted: Mon Dec 25, 2023 7:53 am
by Badem48
Hi,

I am confused about one subject of this option "Multiple inheritance of type includes ability to implement multiple interfaces and/or ability to extend from multiple classes."

At https://docs.oracle.com/javase/tutorial ... tance.html it says "The Java programming language supports multiple inheritance of type, which is the ability of a class to implement more than one interface. An object can have multiple types: the type of its own class and the types of all the interfaces that the class implements. This means that if a variable is declared to be the type of an interface, then its value can reference any object that is instantiated from any class that implements the interface."

However, this option also add "... and/or ability to extend from multiple classes." Is this right?

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

Posted: Mon Dec 25, 2023 10:08 am
by admin
The statement, ""Multiple inheritance of type includes ability to implement multiple interfaces and/or ability to extend from multiple classes." is correct because it means Multiple inheritance of type can be achieved either by implementing multiple interface or by extending from multiple classes or both.

Java doesn't support the ability to extend from multiple classes but that is not what the above statement claims.

Please go through the responses above.

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

Posted: Mon Dec 25, 2023 12:07 pm
by Badem48
I am sorry maybe I am missing something here but on the Oracle documentation it does not mentioned anything about "inheritance of type ... ability to extend from multiple classes" . It is state the fact Java supports multiple inheritance of type by implementing more than one interface.

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

Posted: Mon Dec 25, 2023 8:47 pm
by admin
That is because the Oracle page is talking about Java. The statement in the question is talking about multiple inheritance of type in general.