This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

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

 
Ranch Hand
Posts: 48
  • 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: 73
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
 
She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!