C# Examples
Index
1 2
3
4
5
6
7
8 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 39
40
Example of Inheritance and Constructor in C#
//Inheritance and constructor in C#
class a
{
public a()
{
System.Console.WriteLine("constr a");
}
public virtual void display()
{
System.Console.WriteLine("A");
}
}
class b : a //b is child of a
{
public b()
{
System.Console.WriteLine("constr b");
}
public override void display()
{
System.Console.WriteLine("B");
}
}
class d : b //d is child of b
{
public d()
{
System.Console.WriteLine("constr d");
}
public override void display()
{
System.Console.WriteLine("D");
}
}
class c
{
public static void Main()
{
d x=new d();//Normally object of child
x.display();
}
}
/*
constr calling:- top to bottom
method :- bottom to top
*/
|
Download
Source Code
Index
1 2
3
4
5
6
7
8 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 39 40
Tolal:0 Click:
Show All Comments