Ad Code

Responsive Advertisement

inheritance in c# types - Learn c sharp

Inheritance in c# types - Learn c sharpThe concept of inheritance is an important pillar in the field of Object-Oriented Programming languages, where inheritance is one of the important topics in programming. which has contributed to a great qualitative transfer and made the programming process run in an efficient and orderly manner, and highlights the importance of inheritance in helping users by Reusing pre-written codes and programs and modifying some of them or adding new features instead of rewriting them every time the user needs them, thus saving time and effort and making the process of writing programs easier.


inheritance in c# types - Learn c sharp



Inheritance in C#


Inheritance: is the process of creating and deriving a new class or new class based on the class that was previously defined within the code. It can also add some new features that it wants to use.


Important terms in inheritance, the programming language C#


Superclass: It is the main class, sometimes called (parent class), in which we write a set of properties and functions that are derived and inherited from another class in the program.


Subclass: It is the class that inherits properties and functions from the parent class, and it is sometimes called (a derived class or child class), and the user can add some features and properties that are not inherited from the parent class.


Types of Inheritance in C#


Single Inheritance: In this type of inheritance, a subclass inherits properties, functions, and functions from only one parent class.


Multiple Inheritance: In this type, properties, functions, and functions are inherited from more than one main class, and all characteristics and behaviors of all the parents from which they were inherited are inherited.


Types of inheritance in terms of data access quality in C


  1. Private Inheritance: When a subclass inherits from the main class (superclass) and the inheritance type is private, all data, operations, and properties in the base class become private to the derived class.
  2. Protected Inheritance: In this type, all data and characteristics of the main variables are protected by the subclass as they are in the main classification.
  3. Public Inheritance: In this type, data and operations are distributed as follows:

  • Protected: Data, functions, and properties that are protected in the main class are also protected in the subclass.
  • Public: In this type, all the data and properties of the main taxonomy are generally used in the subclassification.
  • private: never inherited (private data is never inherited).