440 likes | 610 Views
Chapter 10 Classes and Objects: A Deeper Look. C lasses. Classes are not just containers for methods Virtually all are classes Blueprint/Cookie Cutter/Recipe Objects – instance of the class (new) Type “prop” tab tab OOP – vast topic. 10.2 Time Class Case Study.
E N D
Classes • Classes are not just containers for methods • Virtually all are classes • Blueprint/Cookie Cutter/Recipe • Objects – instance of the class (new) • Type “prop” tab tab • OOP – vast topic
Formatting: http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx Padding: http://msdn.microsoft.com/en-us/library/txafckwd.aspx
Class public A protected B internal C private D Class public A protected B internal C private D SubClass (outside package) public A protected B internal C private D SubClass public A protected B internal C private D private D Class (outside package) public A protected B internal C private D ASSEMBLY
10.4 Referring to the Current Object’s Members with the this Reference
10.5 Time Class Case Study: Overloaded Constructors It's the marker for Inheritance and/or the constructor call chain.
What is the difference between constand static readonly? • static readonly field is set at run time, and can thus be modified by the containing class • the value of a const field is set to a compile time constant. • In the staticreadonlycase, the containing class is allowed to modify it only in the variable declaration (through a variable initializer) in the static constructor (instance constructors, if it's not static) • staticreadonlyis typically used if the type of the field is not allowed in a const declaration, or when the value is not known at compile time. • Instancereadonly fields are also allowed. • Remember that for reference types, in both cases (static and instance) the readonly modifier only prevents you from assigning a new reference to the field. It specifically does not make immutable the object pointed to by the reference.