• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

OCA Java SE 8 Programmer I Study Guide from Edward Finegan and Robert Liguori Interactive Quiz on CD

 
Ranch Hand
Posts: 61
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the interactive quiz, I choose exam 2 and this code segment is from question 50.

50. Given the following classes and interface, what ist the output of the code segment?



Solutions:

A. Status: 1 Error: false
B. Status: 2 Error: false
C. Status: 1 Error: true
D. Status: 2 Error: true
E. A compiler error will occur.
F. A runtime error will occur.

I choose solution A, but that was incorrect!!

The explanation is very short and I don't understand it!

Explanation:
E is correct. This will generate a compiler error because a superclass, ClassX, is trying to polymorphically act as a subclass, ClassY.

A, B, C, D, and F are incorrect. B is incorrect; however, if the variable sampleA was initialized as ClassY, it would be correct.




Why is superclass ClassX trying to polymorphically act as a subclass, ClassY?? That answer I don't understand!!! Can someone give me a simple explanation, if it exists one?
What if we add the interface method public boolean errorState();{ return true; } to the ClassY, would then the code compile?

Thanks in advance.


 
Ranch Hand
Posts: 84
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Gualeni wrote:In the interactive quiz, I choose exam 2 and this code segment is from question 50.

50. Given the following classes and interface, what ist the output of the code segment?



Solutions:

A. Status: 1 Error: false
B. Status: 2 Error: false
C. Status: 1 Error: true
D. Status: 2 Error: true
E. A compiler error will occur.
F. A runtime error will occur.

I choose solution A, but that was incorrect!!

The explanation is very short and I don't understand it!

Explanation:
E is correct. This will generate a compiler error because a superclass, ClassX, is trying to polymorphically act as a subclass, ClassY.

A, B, C, D, and F are incorrect. B is incorrect; however, if the variable sampleA was initialized as ClassY, it would be correct.




Why is superclass ClassX trying to polymorphically act as a subclass, ClassY?? That answer I don't understand!!! Can someone give me a simple explanation, if it exists one?
What if we add the interface method public boolean errorState();{ return true; } to the ClassY, would then the code compile?

Thanks in advance.


superclass reference can point to subclass object but not vise versa
Because  a subtype object can be substituted in the supertype reference
Whenever a subtype object is created a supertype object is created implicitly, polymorphic behavior can change the code at runtime with respect to object and also a subclass has some knowledge of superclass that is inherited
Second true does bother for your exicuition
    Bookmark Topic Watch Topic
  • New Topic