What will be the output of the following C# code? [code] class Program { static void Main(string[] args) { Console.WriteLi

thanhthao

New member
What will be the output of the following C# code?
Code:
 class Program
 {
     static void Main(string[] args)
     {
         Console.WriteLine( vol(10));
         Console.WriteLine( vol(2.5f,  5));
         Console.WriteLine( vol( 5l,  4,  5));
         Console.ReadLine();
     }
     static int vol(int x)
     {
         return(x * x * x);
     }
     static float vol(float r,  int h)
     {
         return(3.14f * r * r * h);
     }
     static long vol(long l, int b, int h)
     {
         return(l * b * h);
     }
 }
A.
1000
0
100
B.
0
0
100
C. compile time error
D.
1000
98.125
100
 
Answer: d
Explanation: The concept of method overloading is implemented in method “vol” with same name but different definitions and parameter list which is overloaded three times and each time the return type is different for each method and hence matches the method using types of parameters.
Output:
Code:
        1000
        98.125
        100
 

Tìm kiếm

Back
Top