C# Interview Questions - 15 | Snaprecruit.com

C# Interview Questions - 15 | Snaprecruit.com

C SHARP interview questions part 15

C SHARP interview questions part 15

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. What will be the output of the given code snippet? public class A { public int x; public int y; public void display() { Console.WriteLine(x + " " + y); } } class Program { static void Main(string[] args) { A obj1 = new A(); A obj2 = new A(); obj1.x = 1; obj1.y = 2; obj2 = obj1; obj1.display(); obj2.display(); } }

Correct Answer is : generics are useful in collection classes in .NET framework

2. What will be the output of the given code snippet? class Program{ static void Main(string[] args) { int[] nums = { 1 }; var posNums = from n in nums select Math.Pow(4 ,3); Console.Write("The values in nums: "); foreach (int i in posNums) Console.Write(i + " "); Console.WriteLine(); Console.ReadLine(); }}

Correct Answer is : Generic procedures should take at least one type parameter

3. What will be the output of the given code snippet? class Program{ static void Main(string[] args) { float x = 3.14F; int y = (int)Math.Abs(x); Console.WriteLine(y); Console.ReadLine(); }}

Correct Answer is : Class MyConatiner requires that its type argument must implement Icomparable interface

4. What will be the output of the given code snippet? class Program{ static void Main(string[] args) { int x = 5; int y = (int)Math.Pow(x,2); int z = (int)Math.Pow(y, 2); Console.WriteLine(z); Console.ReadLine(); }}

Correct Answer is : compile time error

5. What will be the output of the given code snippet? class Program { static void Main(string[] args) { int[] nums = {3 ,1 ,2 ,5 ,4}; var ltAvg = from n in nums let x = nums.Average() where n < x select n; Console.WriteLine("The average is " + nums.Average()); Console.ReadLine(); } }

Correct Answer is : SortedDictionary

6. What will be the output of the given code snippet? class Program{ static void Main(string[] args) { int y = (int)Math.Max(4,2); int z = (int)Math.Pow(y, 2); Console.WriteLine(z); Console.ReadLine(); }}

Correct Answer is : 30

7. The process of defining two or more methods within the same class that have same name but different parameters list?

Correct Answer is : C++

8. Which of these can be overloaded?

Correct Answer is : In else

9. What could be the output of the following set of code? class Program { static void Main(string[] args) { Console.WriteLine( vol(10)); Console.WriteLine( vol(2.5f, 5)); Console.WriteLine( vol( 5l, 4, 5)); Console.ReadLine(); } static int vol(int x) { return(x * x * x); } static float vol(float r, int h) { return(3.14f * r * r * h); } static long vol(long l, int b, int h) { return(l * b * h); } }

Correct Answer is : 0 1 2 3

10. What could be the output for the set of code? class overload { public int x; int y; public int add(int a) { x = a + 1; return x; } public int add(int a, int b) { x = a + 2; return x; } } class Program { static void Main(string[] args) { overload obj = new overload(); overload obj1 = new overload(); int a = 0; obj.add(6); obj1.add(6, 2); Console.WriteLine(obj.x); Console.WriteLine(obj1.x); Console.ReadLine(); } }

Correct Answer is : 0 0 1

11. What would be output for the set of code? class maths { public int x; public double y; public int add(int a, int b) { x = a + b; return x; } public int add(double c, double d) { y = c + d; return (int)y; } public maths() { this.x = 0; this.y = 0; } } class Program{ static void Main(string[] args) { maths obj = new maths(); int a = 4; double b = 3.5; obj.add(a, a); obj.add(b, b); Console.WriteLine(obj.x + " " + obj.y); Console.ReadLine(); }}

Correct Answer is : Compile time error

12. What will be output for the given set of code? class maths { public static void fun1() { Console.WriteLine("method 1 :"); } public void fun2() { fun1(); Console.WriteLine("method 2 :"); } public void fun2(int k) { Console.WriteLine(k); fun2(); } } class Program { static void Main(string[] args) { maths obj = new maths(); maths.fun1(); obj.fun2(20); Console.ReadLine(); } }

Correct Answer is : Sachin Tendulkar

13. What is the process of defining a method in terms of itself, that is a method that calls itself?

Correct Answer is : Compile time error

14. What will be the output for the following set of code? class maths { public int fun1(int k) { k = 20; return k; } public Single fun1(float t) { t = 3.4f; return t; } } class Program { static void Main(string[] args) { maths obj = new maths(); int i; i = obj.fun1(30); Console.WriteLine(i); Single j; j = obj.fun1(2.5f); Console.WriteLine(j); Console.ReadLine(); } }

Correct Answer is : java

15. What will be the output for the given set of code? class maths { public int fun(int k, int y) { return k + y; } public int fun1(int t, float z) { return (t+(int)z); } } class Program { static void Main(string[] args) { maths obj = new maths(); int i; int b = 90; int c = 100; int d = 12; float l = 14.78f; i = obj.fun(b, c); Console.WriteLine(i); int j = (obj.fun1(d, l)); Console.WriteLine(j); Console.ReadLine(); } }

Correct Answer is : 45453

16. What will be the output for the set of code? class maths { public int fun(int k, int y, int n) { Console.WriteLine(k + " " + y + " " + n); return (k); } public int fun1(int t,float z) { Console.WriteLine(t + " " + z); return t; } } class Program { static void Main(string[] args) { maths obj = new maths(); int b = 90; int c = 100; int d ; float l; int i = obj.fun(b, c, 12); int j = (obj.fun1(12, 14.78f)); Console.ReadLine(); } }

Correct Answer is : 0 -10

17. What will be the output for the given set of code? class maths { public int fun(int ii) { return(ii > 0 ? ii :ii * -1); } public long fun(long ll) { return(ll > 0 ? ll :ll * -1); } public double fun( double dd) { return(dd > 0 ? dd :dd * -1); } } class Program { static void Main(string[] args) { maths obj = new maths(); int i = -25; int j ; long l = -100000l ; long m; double d = -12.34; double e; j = obj.fun(i); m = obj.fun(l); e = obj.fun(d); Console.WriteLine(j + " " + m + " " + e); Console.ReadLine(); } }

Correct Answer is : 12345B

18. Which keyword is used to declare a base class method while performing overriding of base class methods?

Correct Answer is : 123450

19. The process of defining a method in a subclass having same name & type signature as a method in its superclass is known as?

Correct Answer is : B

20. Which of the given modifiers can be used to prevent Method overriding?

Correct Answer is : -1 0

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon