Users Online
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Latest Articles
Articles Hierarchy
C# Questions & Answers ? Method with Parameters
C# Questions & Answers – Method with Parameters
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
Explanation: None.
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
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
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
Explanation: 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
Explanation: 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
Explanation: None.
Output :
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
Explanation: None.
Output :
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
Explanation: None.
Output :
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
Explanation: None.
Output :
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
Explanation: Both conditions for if statements are failed and hence statement after else is executed.
Output :
2