Introduction to Classes


  1. Example the difference between a public and a private member of a class.

  2. Example the difference between a constructor and a destructor

  3. What name must a constructor have?

  4. What name must a destructor have?


Answers





























































  1. A public member is accessible from outside a class. A private member can only be accessed within the class.

  2. A constructor function is called automatically whenever we instantiate (create) an object of that class and can be used to inialise the object. A destructor is called automatically whenever the scope of the object terminates (ie at the end of the program)

  3. A constructor always has the same name as the class
  4. A destructor has the same name as the class but prefixed with a ~ (tilde)


  5. Back to Questions Back to Main Page for Lecture 9