Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C# Programs Illustrating Inheritance Concepts, Lecture notes of Computer Science

Several c# programs demonstrating various inheritance concepts, including method overloading, method hiding, constructor inheritance, and abstract classes. The programs include examples of single, hierarchical, and multilevel inheritance.

What you will learn

  • What is the purpose of the programs demonstrating multilevel and multiple inheritance?
  • What are the different types of inheritance demonstrated in these programs?
  • How are reference parameters used in the provided C# programs?
  • What is the difference between virtual and abstract classes in these programs?
  • How are named arguments used in these C# programs?

Typology: Lecture notes

2017/2018

Uploaded on 11/03/2018

goldmelu
goldmelu 🇮🇳

1 document

1 / 22

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Programs illustrating Inheritance:
Program#1:
using System;
class Test
{
static void Foo(int x)
{
Console.WriteLine("Foo(int x)");
}
static void Foo(string y)
{
Console.WriteLine("Foo(string y)");
}
static void Main()
{
Foo("text");
}
}
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16

Partial preview of the text

Download C# Programs Illustrating Inheritance Concepts and more Lecture notes Computer Science in PDF only on Docsity!

Programs illustrating Inheritance:

Program#1:

using System;

class Test { static void Foo(int x) { Console.WriteLine("Foo(int x)"); }

static void Foo(string y) { Console.WriteLine("Foo(string y)"); }

static void Main() { Foo("text"); }

Program#2:

using System;

class Test { static void Foo(int x) { Console.WriteLine("Foo(int x)"); }

static void Foo(double y) { Console.WriteLine("Foo(double y)"); }

static void Main() { Foo(10); }

Program#4:

using System;

class Test { static void Foo(int x, double y) { Console.WriteLine("Foo(int x, double y)"); }

static void Foo(double x, int y) { Console.WriteLine("Foo(double x, int y)"); }

static void Main() { Foo(5, 10); }

Program#5:

using System;

class Parent { public void Foo(int x) { Console.WriteLine("Parent.Foo(int x)"); } }

class Child : Parent { public void Foo(double y) { Console.WriteLine("Child.Foo(double y)"); } }

class Test { static void Main() { Child c = new Child(); c.Foo(10); }

Program#

using System;

class Test { static string Foo(int x) { Console.WriteLine("Foo(int x)"); return ""; }

static Guid Foo(double y) { Console.WriteLine("Foo(double y)"); return Guid.Empty; }

static void Main() { Guid guid = Foo(10); }

Program#

using System;

class Test { static void Foo(int x, int y = 5) { Console.WriteLine("Foo(int x, int y = 5)"); }

static void Foo(int x) { Console.WriteLine("Foo(int x)"); }

static void Main() { Foo(10); }

Prograam#

using System;

class Test { static void Foo(int x, int y = 5) { Console.WriteLine("Foo(int x, int y = 5)"); }

static void Foo(double x) { Console.WriteLine("Foo(double x)"); }

static void Main() { Foo(10); }

Program#

using System;

class Test { static void Foo(int x) { Console.WriteLine("Foo(int x)"); }

static void Foo(double y) { Console.WriteLine("Foo(double y)"); }

static void Main() { Foo(y: 10); }

public void Learn()

{

Console.WriteLine("Learn");

}

}

}

Program#13:

  • C# Program to Illustrate Hierarchical Inheritance

*/

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Inheritance

{

class Program

{

static void Main(string[] args)

{

Principal g = new Principal();

g.Monitor();

Teacher d = new Teacher();

d.Monitor();

d.Teach();

Student s = new Student();

s.Monitor();

s.Learn();

Console.ReadKey();

}

class Principal

{

public void Monitor()

{

Console.WriteLine("Monitor");

Program #14:

  • C# Program to Demonstrate Multilevel Inheritance

*/

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Inherit

{

class inherit : vehicle

{

public void Noise()

{

Console.WriteLine("All Vehicles Creates Noise !! ");

}

static void Main(string[] args)

{

inheri obj = new inheri();

obj.mode();

obj.feature();

obj.Noise();

Console.Read();

}

}

class Mode

{

public void mode()

{

Console.WriteLine("There are Many Modes of Transport !!");

}

}

class vehicle : Mode

{

public void feature()

{

Console.WriteLine("They Mainly Help in Travelling !!");

}

}

using System;

class Program

{

static void Main()

{

// Call the Test method several times in different ways.

Test(name: "Perl", size: 5);

Test(name: "Dot", size: -1);

Test(6, "Net");

Test(7, name: "Google");

}

static void Test(int size, string name)

{

Console.WriteLine("Size = {0}, Name = {1}", size, name);

}