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 Constructor In C#
/*Constructor :-
1)It is used to initialize the private attribute of class
2)It is just like method
3)Class name and Constructor name must be same
4)constr can be overloaded
5)Cosntr can be parameterized
6)we don't need to call it.
7)call automatically at the time of object creation
8)when we r not defining any Constructor there will be a default Constructor
9)we don't use any return type
*/
class a
{
private int k;
//Constructor Overloading
public a()//Constructor
{
k=1000;
}
public a(int p)//parameterized Constructor
{
k=p;
}
//Public method
public void display()
{
System.Console.WriteLine("The value of k is -->"+k);
}
}
class b
{
public static void Main()
{
a x=new a();
x.display();
a y=new a(42432) ;
y.display();
}
}
|
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