C# Programming - Constructors - Discussion
Discussion Forum : Constructors - General Questions (Q.No. 18)
18.
What will be the output of the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{
class Sample
{
public static void fun1()
{
Console.WriteLine("Bix1 method");
}
public void fun2()
{
fun1();
Console.WriteLine("Bix2 method");
}
public void fun2(int i)
{
Console.WriteLine(i);
fun2();
}
}
class MyProgram
{
static void Main(string[ ] args)
{
Sample s = new Sample();
Sample.fun1();
s.fun2(123);
}
}
}
Discussion:
9 comments Page 1 of 1.
Sandeep Kr said:
9 years ago
First of all in Main()
fun1() will run and it will return 'Bix1 method'
and then overloaded function fun2(123) will run and return '123'
public void fun2(int i)
{
Console.WriteLine(i);
fun2();
}
and when calling fun2() it will return 'Bix1 Method' because
fun2() calling fun1() which having statement
Console.WriteLine("Bix1 method");
and then fun2() will call its own statement
Console.WriteLine("Bix2 method");
so we have output
Bix1 method
123
Bix1 method
Bix2 method
fun1() will run and it will return 'Bix1 method'
and then overloaded function fun2(123) will run and return '123'
public void fun2(int i)
{
Console.WriteLine(i);
fun2();
}
and when calling fun2() it will return 'Bix1 Method' because
fun2() calling fun1() which having statement
Console.WriteLine("Bix1 method");
and then fun2() will call its own statement
Console.WriteLine("Bix2 method");
so we have output
Bix1 method
123
Bix1 method
Bix2 method
Ajay yadav said:
1 decade ago
@pranjal dear , ur ans is completly wrong jst coz jst see after d call of fun 2 and we pass one sig. so it vl use one sing function n after dat fun 2 further calling fun 2 method who has no sig. so it vl again go for fun 2 n their again calling for fun 1 so all d step vl move sequentially and vl get d write ans dat is A ... hope u understand !! ur ans is incomplete !! or can say wrong !!
Pranjal said:
1 decade ago
We call static method and then only 1method which is taking 1argument then Output should be
Bix1 method
123
so why my ans is wrong please explain it i am not getting it
Bix1 method
123
so why my ans is wrong please explain it i am not getting it
Shafi said:
1 decade ago
@Ajay Yadav.
Please explain how the func2() returns 123.func2() doesn't contains the any parameters then how can we pass the value at the execution time?
Please explain how the func2() returns 123.func2() doesn't contains the any parameters then how can we pass the value at the execution time?
Shaun said:
6 years ago
The static constructors can execute only once. These methods are not constructors and can, therefore, it can be called multiple times.
Soniya said:
1 decade ago
I think answer is:
123.
Bix1 method.
Bix2 method.
Because Sample.fun1(); is not way to call method "fun1()".
123.
Bix1 method.
Bix2 method.
Because Sample.fun1(); is not way to call method "fun1()".
Abdulah said:
1 decade ago
Why not answer?
Class sample bix1 method.
123.
Bix1 method.
Bix2 method.
Class sample bix1 method.
123.
Bix1 method.
Bix2 method.
Anuhya said:
9 years ago
Wrong, because static excuses only once. So
Bix1 method
123
Bix2 method
Bix1 method
123
Bix2 method
Av99 said:
1 decade ago
See the program correctly in fun2.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers