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
View Answer

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

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
View Answer

Answer: c
Explanation: If a static method is present in the program then it will be executed first, then main will be executed.
advertisement
advertisement

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
View Answer

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

Answer: d
Explanation: None.
Note: Join free Sanfoundry classes at Telegram or Youtube

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
View Answer

Answer: c
Explanation: None.
Output :

advertisement
6

7. What will be the output of the following C# code snippet?

advertisement
  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
View Answer

Answer: b
Explanation: None.
Output :

true

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
View Answer

Answer: b
Explanation: None.
Output :

true

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
View Answer

Answer: b
Explanation: None.
Output :

 5

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
View Answer

Answer: b
Explanation: Both conditions for if statements are failed and hence statement after else is executed.
Output :

 2

Sanfoundry Global Education & Learning Series – C# Programming Language.

To practice all areas of C# language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.