C# Questions & Answers on Method with Parameters for Freshers

https://www.computersprofessor.com/2018/08/c-questions-answers-on-method-with.html
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
Answer: d
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
Answer: b
Explanation: Function overloading is a process of defining more than one method in a class with same name differentiated by function signature i:e return type or parameters type and number. Example – int volume(int length, int width) & int volume(int length, int width, int height) can be used to calculate volume.
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
Answer: c
Explanation: If a static method is present in the program then it will be executed first, then main will be executed.
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
Answer: d
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
Answer: d
6. What will be the output of the program?
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
b) 1
c) 6
d) 25
Answer: c
Output :6
7. What will be the output of the given 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
b) true
c) 0
d) 1
Answer: b
Output :true
8. What will be the output of the given 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
b) true
c) 0
d) 1
Answer: b
Output :true
9. What will be the output of the given 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
b) 5
c) 25
d) 26
Answer: b
Output : 5
10. What will be the output of the given 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
b) 2
c) Run time error
d) Compile time error
Answer: b
Explanation: Both conditions for if statements are failed and hence statement after else is executed.
Output : 2