














Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!















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:
*/
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:
*/
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);
}