CS174: Classes And Inheritance: public, private, static

Developed by Professor Tralie and Professor Mongan.


Please watch the video below, and click the next button once you have finished

Notes

  • private variables in a class can only be accessed from within class member methods. This is one mechanism we have for information hiding, or the process of only letting users of our class know what they need to know to avoid confusing them, and also so we have controlled access points to variables where we can do bounds checking, etc at runtime. This all leads to better, more robust code
  • Variables or methods declared as static within a class belong to the whole class, not to an individual object. For instance, we can have a static variable that counts how many objects of this class have been instantiated.