• 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

Mughal's mock exam erratum

 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.
I have found the following erratum in Mughal's mock exam:
--------------------------
QUESTION:
Given that Thing is a class, how many objects and reference variables are created by the following code?
Thing item, stuff;
item = new Object();
Thing entity = new Object();
Select all valid answers:
(A) One object is created.
(B) Two objects are created.
(C) Three objects are created.
(D) One reference variable is created.
(E) Two reference variables are created.
(F) Three reference variables are created.
----------------------
CORRECT ANSWER:
None, since Object is not assignment-compatible to Thing.
----------------------
"CORRECT" ANSWER ACCORDING TO MUGHAL:
(B)+(F). This would have been correct if and only if the objects created were not instances of Object, but of Thing or of a subclass of Thing.
Panagiotis.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did not see anything wrong with the answer given.

-Howard
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm .. you're right Panagiotis ... the code wouldn't compile unless a cast was used. If it did compile correctly then B and F would be right.
Jane
------------------
Jane Griscti
Sun Certified Java 2 Programmer
"When ideas fail, words come in very handy" -- Goethe
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jane Griscti:
Hmmm .. you're right Panagiotis ... the code wouldn't compile unless a cast was used. If it did compile correctly then B and F would be right.
Jane


Jane it wont run even if it is cast to Thing it will give illegal cast exception.
If Thing or itz subclasses are used then the qnswers are correct
Cherry
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cherry,
You're right, there would be a Runtime error.
------------------
Jane Griscti
Sun Certified Java 2 Programmer
"When ideas fail, words come in very handy" -- Goethe
 
I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic