Presentation is loading. Please wait.

Presentation is loading. Please wait.

C#.Net Software Development Version 1.0. Overview Inheritance Member Access Constructors Polymorphism (Name Hiding) Multilevel Hierarchy Virtual and VTable.

Similar presentations


Presentation on theme: "C#.Net Software Development Version 1.0. Overview Inheritance Member Access Constructors Polymorphism (Name Hiding) Multilevel Hierarchy Virtual and VTable."— Presentation transcript:

1 C#.Net Software Development Version 1.0

2 Overview Inheritance Member Access Constructors Polymorphism (Name Hiding) Multilevel Hierarchy Virtual and VTable Abstract, Sealed and Static Up Casting & Down Casting System.Object most base class 2Copyright © 2008 by Dennis A. Fairclough all rights reserved.

3 Inheritance Class Single Inheritance Hierarchy Interface Multiple Inheritance Hierarchy (later) Most (ultimate) base class is always object (System.Object) class X : object (X inherits object) { … } class Y : X (Y inherits X) { … } class Z : Y (Z inherits Y) { … } 3Copyright © 2008 by Dennis A. Fairclough all rights reserved.

4 Inheritance (2) C# Standard When a type inherits from a base class, all members of the base class, except instance constructors, destructors and static constructors, become members of the derived type. The declared accessibility of a base class member does not control whether the member is inherited— inheritance extends to any member that isn’t an instance constructor, static constructor, or destructor. However, an inherited member may not be accessible in a derived type, either because of its declared accessibility (§3.5.1) or because it is hidden by a declaration in the type itself (§3.7.1.2). 4Copyright © 2008 by Dennis A. Fairclough all rights reserved.

5 Member Access private object access protected internal program & inherited protected inherited internal program public anyone 5Copyright © 2008 by Dennis A. Fairclough all rights reserved.

6 Access Modifiers AccessibilityMeaning public Access not limited protected Access limited to this class or classes derived from this class internal Access limited to this program protected internal Access limited to this program or classes derived from this class private Access limited to this class 6Copyright © 2008 by Dennis A. Fairclough all rights reserved.

7 Constructors Default Parameterized Overloaded Calling base class constructor (: base(…)) Sequence of constructor calls Bottom-Up Call Top-Down Completion 7Copyright © 2008 by Dennis A. Fairclough all rights reserved.

8 Destructors & Finalize Same name as the containing class ~Data(){ … } No overloading or overiding allowed Calling order Bottom-Up Call Top-Down Completion Finalize() 8Copyright © 2008 by Dennis A. Fairclough all rights reserved.

9 Polymorphism Hiding Inherited Member Variables Inherited Member Methods Virtual overriding Inherited Member Methods 9Copyright © 2008 by Dennis A. Fairclough all rights reserved.

10 Multilevel Hierarchy “n” deep hierarchy Most (ultimate) base class (System.Object) Base class Most derived class object Dn D1 D0... 10Copyright © 2008 by Dennis A. Fairclough all rights reserved.

11 Virtual & VTable Virtual Methods Vtable override new 11Copyright © 2008 by Dennis A. Fairclough all rights reserved.

12 Abstract, Sealed & Static abstract – Must be inherited from sealed – Cannot be inherited from static class – No “this” pointer cannot be inherited from partial – Split a class across files or code segments 12Copyright © 2008 by Dennis A. Fairclough all rights reserved.

13 Casting Upcasting (Widening Cast) long x = 200; int y = 100; x = y; implicit with no potential loss of precision Downcasting (Narrowing Cast) y = x; //compiler error with potential loss of precision y = (int)x; //explicit cast to over rule the compiler 13Copyright © 2008 by Dennis A. Fairclough all rights reserved.

14 System.Object (object) class NameDescription ObjectInitializes a new instance of the Object class. NameDescription EqualsOverloaded. Determines whether two Object instances are equal. GetHashCodeServes as a hash function for a particular type. GetHashCode is suitable for use in hashing algorithms and data structures like a hash table. Get TypeGets the Type of the current instance. ReferenceEqualsDetermines whether the specified Object instances are the same instance. ToStringReturns a String that represents the current Object. NameDescription FinalizeAllows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. MemberwiseCloneCreates a shallow copy of the current Object. 14Copyright © 2008 by Dennis A. Fairclough all rights reserved.

15 What did you learn? Single inheritance hierarchy’ Polymorphism – inheritance/virtual (VTABLE) override/new shadow variable/method base Access Modifiers – visability All inheritance “public” 15Copyright © 2008 by Dennis A. Fairclough all rights reserved.


Download ppt "C#.Net Software Development Version 1.0. Overview Inheritance Member Access Constructors Polymorphism (Name Hiding) Multilevel Hierarchy Virtual and VTable."

Similar presentations


Ads by Google