-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatic-method-Variable-Constructor
More file actions
59 lines (46 loc) · 1.37 KB
/
Copy pathStatic-method-Variable-Constructor
File metadata and controls
59 lines (46 loc) · 1.37 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Person
{
static int a;
int i;
static Person()
{
Console.WriteLine("hello static Constructor.");
}
public void setval(int n)
{
a = n; //Initilizing the Static variable
i = n;
}
public static void check()
{
Console.WriteLine("Hello static method check");
Check1();
}
static void Check1()
{
Console.WriteLine("Checking...");
Person p = new Person();
p.display();//accessing the non static method in Static method for that u have to Create the object !!.
p.i = 0;//aceesing the Non static variable in Static method
}
public void display()
{
Check1(); //calling Static method from non static method
Console.WriteLine("value of Static varible ={0}",a);
Console.WriteLine("value of Implict varible ={0}", i);
}
}
class Program
{
static void Main(string[] args)
{
Person p = new Person();
Console.WriteLine("hello i am in main");
p.setval(10);
p.display();
Person p1 = new Person();
p1.display();
Person.check();
Console.ReadKey();
}
}