Class 'Sample' is doing all the work... the class 'MyProgram' is calling the shots. let's look @ 'MyProgram'
Code:
Sample s = new Sample();
this is creating a new object of the class 'Sample'. Since there is no constructor telling it to do anything, it is just going to sit there and await instruction.
try to access fun1 via 's'.... you can't (ie s.fun1() will not compile). To access the static method you use the class name.method, in this case "Sample.fun1();"
and finally
this is saying use the method "fun2" that is part of the object "s" (remember he is sitting there waiting instruction). The method "fun2" accepts an integer as an argument (fun2( int i) ) and ypu are passing it the int '123'... then after it writes this to the console, it calls another method within the class "fun2()" (notice without any arguments) and then executes that function. IMO that is really sloppy, it shouldn't be on one line like that... again my opinion it should look more like
Code:
class MyProgram
{
static void Main(string[] args)
{
Sample s = new Sample();
Sample.fun1();
s.fun2(123);
Console.ReadLine();
}
}
class Sample
{
public static void fun1()
{
Console.WriteLine("fun1");
}
public void fun2()
{
Console.WriteLine("fun2");
}
public void fun2(int i)
{
Console.WriteLine(i);
fun2();
}
}
}
See how much easier it is to read? Also note the readline() is so you can see the output.