• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mughal's mock exam erratum

 
Panagiotis Varlagas
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • 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.
 
Howard Hu
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not see anything wrong with the answer given.

-Howard
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • 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
 
Cherry Mathew
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic