• 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

Variables

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

Answer Given :B
I thought D because there is no derived class constructor .
Also I felt C, Can we cast a base class reference into derived class in base class itself .?How does it work

Cheers
Smitha
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regarding D, the compiler automatically provides a default no-arg constructor if none exists. That's the constructor that gets called when DerivedQ48 is new'ed into existence.

Regarding C, remember the object you created is actually an instance of DerivedQ48. Even though you've assigned it to a TestQ48 reference variable (which basically says, "treat me like I'm a TestQ48 object") the underlying object is still an instance of DerivedQ48. Therefore, when you cast it back to its original class, there is no error.

The reverse would not be true.



The first line would give you a conversion error because you're trying to go backwards down the hierarchy.
 
Everybody! Do the Funky Monkey! Like this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic