0% found this document useful (0 votes)
4 views14 pages

C# Inheritance: Types and Concepts

The document explains inheritance in C#, which allows for the reuse of existing classes by creating new derived classes that incorporate properties and methods from base classes. It highlights key characteristics of inheritance, such as the ability to add new members and the limitations on modifying inherited members. Additionally, it notes that C# does not support multiple inheritance directly but allows for similar functionality through interfaces.

Uploaded by

hadismsmanii
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views14 pages

C# Inheritance: Types and Concepts

The document explains inheritance in C#, which allows for the reuse of existing classes by creating new derived classes that incorporate properties and methods from base classes. It highlights key characteristics of inheritance, such as the ability to add new members and the limitations on modifying inherited members. Additionally, it notes that C# does not support multiple inheritance directly but allows for similar functionality through interfaces.

Uploaded by

hadismsmanii
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

 Describe inheritance and its types in C#

 It is always nice if we could reuse something that already


exists rather than creating the same over again.
 C# classes can be reused in several ways.
 Reusability is achieved by designing new classes, reusing all
or some of the properties of easting ones.
 The mechanism of designing or constructing one class from
another is called inheritance.
 Inheritance represents a kind of relationship between two classes.

 A derived class is a completely new class that incorporates all the data and
methods of its base class.
 It can also have its own data and method members that are unique to
itself.
public class Person

public void Greet()

[Link]("Hello, I’m a new person!");

public class Student : Person

}
Person p = new Person(); // creates a new object of Person class
[Link](); //calls Greet () method
Student s = new Student(); // creates a new object of Student class
[Link](); //calls Greet () method

Even though the Greet() method is not defined in the Student class,
any object of Student class can access the Greet() method through
inheritance.
C# does not directly implement multiple inheritance, however, this concept is
implemented using a secondary inheritance path in the form of interfaces.
Some important characteristics of inheritance are:

•A derived class extends its direct base class.


•It can add new members to those it inherits.
•However, it cannot change or remove the definition of an inherited
member.
•Constructors and destructors are not inherited.
•All other members, regardless of their declared accessibility in base class,
are inherited. However, their accessibility in the derived class depends on
their declared accessibility in the base class.
•A derived class can hide an inherited member
•A derived class can override an inherited member
Continue…
 This chapter explains:-

›Inheritance and different types of inheritance.

You might also like