This section of our 1000+ C# MCQs focuses on method with parameters in C# Programming Language.
1. Which of these data types can be used for a method having a return statement in it?
a) void
b) int
c) float
d) all of the mentioned
2. What is the process of defining more than one method in a class differentiated by parameters known as?
a) Function overriding
b) Function overloading
c) Function doubling
d) None of the mentioned
3. Which of these methods is executed first before execution of any other thing that takes place in a program?
a) main method
b) finalize method
c) static method
d) private method
4. Which of these can be used to differentiate two or more methods having same name?
a) Parameters data type
b) Number of parameters
c) Return type of method
d) All of the mentioned
5. Which of these data types can be used for a method having a return statement in it?
a) void
b) int
c) float
d) all of the mentioned
6. What will be the output of the following C# code?
class box
{
int width;
int height;
int length;
int volume;
void volume(int height, int length, int width)
{
volume = width * height * length;
}
}
class Prameterized_method
{
public static void main(String args[])
{
box obj = new box();
obj.height = 1;
obj.length = 5;
obj.width = 5;
obj.volume(3, 2, 1);
Console.WriteLine(obj.volume);
Console.ReadLine();
}
}
a) 0
b) 1
c) 6
d) 25
6
7. What will be the output of the following C# code snippet?
class equality
{
int x;
int y;
boolean isequal()
{
return(x == y);
}
}
class Output
{
public static void main(String args[])
{
equality obj = new equality();
obj.x = 5;
obj.y = 5;
Console.WriteLine(obj.isequal());
}
}
a) false
b) true
c) 0
d) 1
true
8. What will be the output of the following C# code snippet?
class equality
{
public int x;
public int y;
public Boolean isequal()
{
return (x == y);
}
}
class Program
{
static void Main(string[] args)
{
equality obj = new equality();
obj.x = 5;
obj.y = 5;
Console.WriteLine(obj.isequal());
Console.ReadLine();
}
}
a) false
b) true
c) 0
d) 1
true
9. What will be the output of the following C# code snippet?
class box
{
public int width;
public int height;
public int length;
public int volume1;
public void volume()
{
volume1 = width * height * length;
}
public void volume(int x)
{
volume1 = x;
}
}
class Program
{
static void Main(string[] args)
{
box obj = new box();
obj.height = 1;
obj.length = 5;
obj.width = 5;
obj.volume(5);
Console.WriteLine(obj.volume1);
Console.ReadLine();
}
}
a) 0
b) 5
c) 25
d) 26
5
10. What will be the output of the following C# code snippet?
class Program
{
static void Main(string[] args)
{
int x, y = 1;
x = 10;
if(x != 10 && x / Convert.ToInt32(0) == 0)
Console.WriteLine(y);
else
Console.WriteLine(++y);
Console.ReadLine();
}
}
a) 1
b) 2
c) Run time error
d) Compile time error
2