250+ TOP MCQs on Method with Parameters and Answers

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?
a) void
b) int
c) float
d) all of the mentioned

Answer: d
Clarification: 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

Answer: b
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.

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
Clarification: 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
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?

  1. class box
  2. {
  3.     int width;
  4.     int height;
  5.     int length;
  6.     int volume;
  7.     void volume(int height, int length, int width)
  8.     {
  9.         volume = width * height * length;
  10.     }
  11. }
  12. class Prameterized_method
  13. {
  14.     public static void main(String args[])
  15.     {
  16.        box obj = new box();
  17.        obj.height = 1;
  18.        obj.length = 5;
  19.        obj.width = 5;
  20.        obj.volume(3, 2, 1);
  21.        Console.WriteLine(obj.volume);
  22.        Console.ReadLine();
  23.     }
  24. }

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?

  1. class equality
  2. {
  3.     int x;
  4.     int y;
  5.     boolean isequal()
  6.     {
  7.         return(x == y);
  8.     }
  9. }
  10. class Output
  11. {
  12.     public static void main(String args[])
  13.     {
  14.        equality obj = new equality();
  15.        obj.x = 5;
  16.        obj.y = 5;
  17.        Console.WriteLine(obj.isequal());
  18.     }
  19. }

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?

  1.  class equality
  2.  {
  3.      public  int x;
  4.      public int y;
  5.      public Boolean isequal()
  6.      {
  7.          return (x == y);
  8.      }
  9.  }
  10.  class Program
  11.  {
  12.      static void Main(string[] args)
  13.      {
  14.          equality obj = new equality();
  15.          obj.x = 5;
  16.          obj.y = 5;
  17.          Console.WriteLine(obj.isequal());
  18.          Console.ReadLine();
  19.      }
  20.  }

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?

  1. class box
  2. {
  3.     public  int width;
  4.     public int height;
  5.     public int length;
  6.     public  int volume1;
  7.     public void volume()
  8.     {
  9.         volume1 = width * height * length;
  10.     }
  11.     public void volume(int x)
  12.     {
  13.         volume1 = x;
  14.     }
  15. }
  16. class Program
  17. {
  18.     static void Main(string[] args)
  19.     {
  20.         box obj = new box();
  21.         obj.height = 1;
  22.         obj.length = 5;
  23.         obj.width = 5;
  24.         obj.volume(5);
  25.         Console.WriteLine(obj.volume1);
  26.         Console.ReadLine();
  27.     }
  28. }

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?

  1. class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         int x, y = 1;
  6.         x = 10;
  7.         if(x != 10 && x / Convert.ToInt32(0) == 0)
  8.         Console.WriteLine(y);
  9.         else
  10.         Console.WriteLine(++y);
  11.         Console.ReadLine();
  12.     }
  13. }

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 :

Leave a Reply

Your email address will not be published. Required fields are marked *