• 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

Test Banks Wiley Chapter 5 Q2

 
Ranch Hand
Posts: 40
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Answers:

A. Platypus

B. Mammal

C. PlatypusMammal

D. MammalPlatypus

E. The code will not compile because of line 8.

F. The code will not compile because of line 11.


The explanation given is not good:

E.
The code will not compile because the parent class Mammal doesn’t define a no-argument constructor, so the first line of a Platypus constructor should be an explicit call to super(int age). If there was such a call, then the output would be MammalPlatypus, since the super constructor is executed before the child constructor.


My interpretation:

If there was super(2); for example inserted in first line of Platypus constructor then it will just print Mammal. Writer saying it will print MammalPlatypus. I've compiled and my view is correct.

Is there a rule for this. So say

class C extends B
class B extends A

They all have constructors with a different print out e.g. "A" "B" "C".

If I call A it will just print "A", if I call C it will print A,B and C ?

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
E is correct. Please explain what you don't understand about the explanation. You are however correct that line 15 will not cause “Platypus” to be printed. I don't know where the errata page is.

Please maintain indentation when you copy code, and don't write line numbers in code tags. That makes it much easier to test the code.
 
Niall Kev
Ranch Hand
Posts: 40
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I fully understand now. It was just the explanation they provided threw me off course. They suggested that you put super(int age) as first line of Platypus and in turn that would print MammalPlatypus.

The sybex wiley questions seem alot easier than enthuware. Are they more similar to the real exam?
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Niall Kev wrote:Thanks. . . .

That's a pleasure
 
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

Niall Kev wrote:The sybex wiley questions seem alot easier than enthuware. Are they more similar to the real exam?


We are intending for them to be similar in difficulty to the real exam.
reply
    Bookmark Topic Watch Topic
  • New Topic