• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OO Concepts (Enthuware)

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found these statements in a mock exam:

- 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.
- Multiple inheritance of type includes ability to implement multiple interfaces and/or ability to extend from multiple clases.

They are true.

Explanation

Interfaces, classes, and enums are all "types". Java allows a class to implement multiple interfaces. In this way, Java supports multiple inheritance of types.
"State", on the other hand, is represented by instance fields and instance methods. Only a class can have instance fields/methods and therefore, only a class can have a state. (Fields defined in an interface are always implicitly static, even if you don't specify the keyword static explicitly. Therefore, an interface does not have any state.) Since a class is allowed to extend only from one class at the most, it can inherit only one state. Thus, Java does not support multiple inheritance of state.

I understand the explanation, but I do not understand why the first two statements are true.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I moved this thread to the OCA forum since it is from a mock exam. I also edited the subject to indicate where the mock exam is from. Please cite this going forward.

I found a thread on Enthuware where Paul says it is correct.

I don't like the question because Java doesn't support multiple inheritance of state. (as the explanation notes). So it isn't something you need to know in the first place for the exam. If Java did allow multiple inheritance of classes, then these statements would be true.

Back to what Java does support - remember that interfaces can declare concrete methods in Java 8. So you can inherit default methods from multiple interfaces.
 
Enthuware Software Support
Posts: 4810
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have confirmed reports from test takers that they got a question on this. This question was added only recently after getting multiple reports from test takers.

The explanation and answers are based on this official tutorial:
https://docs.oracle.com/javase/tutorial/java/IandI/multipleinheritance.html


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.



The option does not  say that java suppprts multiple inheritance of state .
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Anilprem wrote:The option does not  say that java suppprts multiple inheritance of state .


Oh good. I haven't seen the question. The answers imply the question is about multiple inheritance of state.
 
Paul Anilprem
Enthuware Software Support
Posts: 4810
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the correct link to the thread on Enthuware : http://enthuware.com/forum/viewtopic.php?f=2&t=4233
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic