|
Hai Dave Hawk..
class Sample
{
public static void fun1() \\ Step 3: fun1() function definition.
{
Console.WriteLine("fun1"); \\ Step 4: Print the first output:"fun1". then go to main function
}
public void fun2() \\ Step 8: fun2() function definition
{
Console.WriteLine("fun2"); \\ step 9: print the Third output:"fun2"
}
public void fun2(int i) \\ Step 6:fun2(123) function definition.
{
Console.WriteLine(i); fun2(); \\ Step 7: Print the value Second output:"123" then callling the fun2() function(passing without parameter)
}
class MyProgram
{
static void Main(string[] args)
{
Sample s = new Sample(); \\ Step 1: create a object s.(i.e class name:Sample object name:s)
Sample.fun1(); \\ Step 2: calling the fun1() fuction. Calling based on classname
s.fun2(123); \\ Step 5: objectname(s) s.fun2(123) . calling based on objectname.(passing parameter)
}
}
}
}
The following steps are how to the above program executed:
Step 1: create a object s.(i.e class name:Sample object name:s)
Step 2: calling the fun1() fuction. Calling based on classname
Step 3: fun1() function definition.
Step 4: Print the first output:"fun1". then go to main function
Step 5: objectname(s) s.fun2(123) . calling based on objectname.(passing parameter)
Step 6:fun2(123) function definition.
Step 7: Print the value Second output:"123" then callling the fun2() function(passing without parameter)
Step 8: fun2() function definition
step 9: print the Third output:"fun2"
Output:
fun1
123
fun2
|