www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons C# Method Hiding and Overriding Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
In this lesson we will explore the methods with respect to OOP.

Inheritance is a very powerful feature of Object Oriented Programming, without which true OOP is nearly impossible. From your past programming experience you should have a sold underrstanding of classes, subclasses, interfaces and polymorphism etc. You must also be familiar with the new keyword and its usage. Inheritance in C# has the same meaning and implications as in Java and C++. We use : to indicate that one class inherits from the other class or a class implements an interface.

public class SubClass : SuperClass

Method Hiding and Overriding

The main difference between hiding and overriding relates to the choice of which method to call where the declared class of a variable is different to the run-time class of the object it references. For example:

//Super class method public virtual double getArea()
return length * width;
//Sub class method public override double getArea()
return length * length;

For one method to override another, the overridden method must not be static, and it must be declared as either 'virtual', 'abstract' or 'override'. Now look at the following:

//Super class method public double getArea()
return length * width;
//Sub class method public new double getArea()
return length * length;

Where one method 'hides' another, the hidden method does not need to be declared with any special keyword. Instead, the hiding method just declares itself as 'new'.
Next >>> Lesson No. 18: C# Exception Handling

Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.