C# MCQs 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? Answer: d 2. What is
the process of defining more than one method in a class differentiated by parameters known as? Answer: b 3. Which of these methods is executed first before execution of any other thing that takes place in a program? Answer: c 4. Which of these can be used to differentiate two or more methods having
same name?
a] void
b] int
c] float
d] all of the mentioned
Clarification: None.
a] Function overriding
b] Function overloading
c] Function doubling
d] None of the mentioned
Clarification: 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.
a] main method
b] finalize method
c] static method
d] private method
Clarification: If a static method is present in the program then it will be executed first, then main will be executed.
a] Parameters data type
b] Number of parameters
c] Return type of method
d] All of the mentioned
Answer: d
Clarification: None.
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
Clarification: None.
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
Answer: c
Clarification: None.
Output :
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
Answer: b
Clarification: None.
Output :
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
Answer: b
Clarification: None.
Output :
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
Answer: b
Clarification: None.
Output :
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
Answer: b
Clarification: Both conditions for if statements are failed and hence statement after else is executed.
Output :