csci3081/class-repo-public/Exercises/Inheritance
Michael Zhang 1ba4536588
f
2018-01-29 17:24:20 -06:00
..
object.cpp f 2018-01-29 17:24:20 -06:00
readme.md f 2018-01-29 17:24:20 -06:00

ComposedClass

  1. Uncomment each of the 'cout' statements, explain why it doesn't compile:
    • privateVar
    • protectedVar
    • object.privateVar
    • object.protectedVar
  2. Uncomment the declaration of privateVar and protectedVar inside the ComposedClass definition.
    • Which of the 'cout' statements can now be successfully compiled? Why?
  3. ComposedClass probably needs to interact with _object_ members. How will you give it access?

DerivedClass

  1. Uncomment each of the 'cout' statements, determine which successfully compiles and explain why or why not:
    • privateVar
    • protectedVar
    • ObjectClass::privateVar
    • ObjectClass::protectedVar
  2. How is it that you redefined _print()_ in the derived class, and yet you can still call _print()_ in the ObjectClass?
  3. In main, the declaration of isAobject_4_5(4,5) is commented out because it will not compile. Why not? There isn't a constructor for DerivedClass with no parameters and that works.
  4. Uncomment the DerivedClass constructor that has no parameters (i.e. 'DerivedClass() :' ). - Determine which of the cout statements compiles and explain why.
  5. Uncomment the members privateVar and protectedVar in DerivedClass, and modify comments in the code so that DerivedClass() : sets those vars to 20 and 25.
    • Report the values for each 'cout' in Derived and explain the results.
  6. In main, now fix DerivedClass so that the statement 'DerivedClass isAobject_4_5(4,5)' works.