• 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

problem from khalid's book

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello
in problem 1.4 (review questions,chapter 1)in Khalid's book it is given that Thing is a class and how many objects and reference variables are created by the following code
Thing item, stuff;
item = new Object();
Thing entity = new Object();
According to me the answer should be no object is created and three reference variables are created as creating an object involves using the new operator togather with a call to constructor of the class(given on page 4 in book under topic "class instantiation") and 'Object()' is not a constructor of class Thing as constructor always has the same name as that of the class.But answers given in the book on page 623 shows that options b and f are true which shows that two objects and three reference variables are created.i could not understand this.please explain this if anybody knows.any help will be highly appreciated.
Thanks
Smriti Singla
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Smriti,
You are correct in assuming that the Compiler will most likely complain about assigning instance Object to instance Thing. I think this was corrected in the book errata ...
Correct problem:

Using the above corrected code, the results stated by Khalid are correct.
Regards,
Manfred.
 
reply
    Bookmark Topic Watch Topic
  • New Topic