1.

What is inheritance? Does C# support multiple inheritance?

Answer»

Inheritance means acquiring some of the properties from a master CLASS

Multiple Inheritance in C#

Here, class C can inherit properties from Class A and Class B. Here is an example of inheritance: 

// C# program to illustrate// multiple class inheritanceusing System;using System.Collections;// Parent class 1class Scaler { // Providing the implementation // of features() METHOD public void features() { // Creating ArrayList ArrayList My_features= new ArrayList(); // Adding elements in the // My_features ArrayList My_features.Add("Abstraction"); My_features.Add("ENCAPSULATION"); My_features.Add("Inheritance"); Console.WriteLine("Features provided by OOPS:"); FOREACH(var elements in My_features) { Console.WriteLine(elements); } }}// Parent class 2class Scaler2 :Scaler{ // Providing the implementation // of courses() method public void languages() { // Creating ArrayList ArrayList My_features = new ArrayList(); // Adding elements in the // My_features ArrayList My_features.Add("C++"); My_features.Add("C#"); My_features.Add("JScript"); Console.WriteLine("\nLanguages that use OOPS CONCEPTS:"); foreach(var elements in My_features) { Console.WriteLine(elements); } }}// Child classclass ScalertoScaler : Scaler2 {}public class Scaler1 { // Main method static public void Main() { // Creating object of ScalertoScaler class ScalertoScaler obj = new ScalertoScaler(); obj.features(); obj.languages(); }}

Also, C# doesn’t support multiple inheritances. 
Instead, you can use interfaces to inherit the properties using the class name in the signature.



Discussion

No Comment Found