C SHARP interview questions part 8

C SHARP interview questions part 8

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

Total Questions: 20

1. What will be the output of given code snippet? { try { int []a = {1, 2, 3, 4, 5}; for (int i = 0; i < 7; ++i) Console.WriteLine(a[i]); } catch(IndexOutOfRangeException e) { Console.WriteLine("0"); } Console.ReadLine();}

Correct Answer is : prints reverse of x

2. What would be the output of following code snippet? { try { int a, b; b = 0; a = 10 / b; Console.WriteLine("A"); } catch(ArithmeticException e) { Console.WriteLine("B"); } Console.ReadLine(); }

Correct Answer is : It finds octal equivalent of i

3. What would be the output of following code snippet? { try { int i, sum; sum = 10; for (i = -1 ;i < 3 ;++i) { sum = (sum / i); Console.WriteLine(i); } } catch(ArithmeticException e) { Console.WriteLine("0"); } Console.ReadLine(); }

Correct Answer is : do

4. What would be the output of following code snippet? { try { int a, b; b = 0; a = 5 / b; Console.WriteLine("A"); } catch(ArithmeticException e) { Console.WriteLine("B"); } finally { Console.WriteLine("C"); } Console.ReadLine(); }

Correct Answer is : 10

5. What would be the output of given code snippet? class Program { static void Main(string[] args) { int i; int v = 40; int[] x = new int[5]; try { Console.WriteLine(" Enter the number: "); index = Convert.ToInt32(Console.ReadLine()); x[index] = v; } catch(Exception e) { Console.WriteLine("Exception occurred"); } Console.WriteLine("Program executed"); } }

Correct Answer is : 1 1 1 1 1 1

6. When is no exception thrown at runtime then who will catch it?

Correct Answer is : 1 2 3 4 5 6 7 8 9 10

7. What would be the output of given code snippet? public static void Main(string[] args) { try { int a, b, c = 5; b = 0; a = c / b; Console.WriteLine("A"); } catch (ArithmeticException e) { int c = 5; int i = 10; int z = 2 * c - i; Console.WriteLine("B"); Console.WriteLine(z); } Console.ReadLine(); }

Correct Answer is : 12045

8. Select the correct output for the given set of code? class sample { public int i; void display() { Console.WriteLine(i); }} class sample1 : sample { public int j; public void display() { Console.WriteLine(j); }} class Program{ static void Main(string[] args) { sample1 obj = new sample1(); obj.i = 1; obj.j = 2; obj.display(); Console.ReadLine(); }}

Correct Answer is : An enum variable cannot have a protected access modifier

9. The following set of code is run on single level of inheritance. Find correct statement about the code? class sample { int i = 10; int j = 20; public void display() { Console.WriteLine("base method "); } } class sample1 : sample { public int s = 30; } class Program { static void Main(string[] args) { sample1 obj = new sample1(); Console.WriteLine("{0}, {1}, {2}", obj.i, obj.j, obj.s); obj.display(); Console.ReadLine(); } }

Correct Answer is : When the valid range of byte exceeds, the compiler will report an error

10. What will be size of the object created depicted by csharp code snippet? class baseclass { private int a; protected int b; public int c; } class derived : baseclass { private int x; protected int y; public int z; } class Program { static Void Main(string[] args) { derived a = new derived(); } }

Correct Answer is : An enum can have Single and Double values

11. What would be output of the following set of code? class sample{ public sample() { Console.WriteLine("THIS IS BASE CLASS constructor"); } } public class sample1 : sample { } class Program{ static void Main(string[] args) { sample1 obj = new sample1(); Console.ReadLine(); }}

Correct Answer is : compile time error

12. Select the statement which should be added to the current set of code to get the output as 10 20 ? class baseclass{ protected int a = 20;}class derived : baseclass{ int a = 10; public void math() { /* add code here */ } }

Correct Answer is : 45302

13. Correct statement about the following C#.NET code is? class baseclass { int a; public baseclass(int a1) { a = a1; console.writeline(" a "); } class derivedclass : baseclass { public derivedclass (int a1) : base(a1) { console.writeline(" b "); } } class program { static void main(string[] args) { derivedclass d = new derivedclass(20); } } }

Correct Answer is : a

14. Which statement should be added in function a() of class y to get output “i love csharp”? class x { public void a() { console.write("bye"); } } class y : x { public void a() { /* add statement here */ console.writeline(" i love csharp "); } } class program { static void main(string[] args) { y obj = new obj(); obj.a(); } }

Correct Answer is : red

15. Select the output for the following set of code? class A { public int i; protected int j;} class B : A { public int j; public void display() { base.j = 3; Console.WriteLine(i + " " + j); }} class Program{ static void Main(string[] args) { B obj = new B(); obj.i = 1; obj.j = 2; obj.display(); Console.ReadLine(); }}

Correct Answer is : Values of the enum elements cannot be populated from database

16. Select the output of the following set of code? class A { public int i; private int j; } class B :A { void display() { base.j = base.i + 1; Console.WriteLine(base.i + " " + base.j); }} class Program{ static void Main(string[] args) { B obj = new B(); obj.i = 1; obj.j = 2; obj.display(); Console.ReadLine(); }}

Correct Answer is : In C, language variables of enum types can be used interchangeably with integers using type casts while enum variables cannot be used as a normal integers in C#.NET

17. Which of these keywords is used to refer to member of base class from a sub class?

Correct Answer is : finally

18. Which of these operators must be used to inherit a class?

Correct Answer is : Both finally & catch

19. Select output for the following set of code. static void Main(string[] args) { int a = 5; int b = 10; int c; Console.WriteLine(c = ++ a + b ++); Console.WriteLine(b); Console.ReadLine(); }

Correct Answer is : ArithmeticException

20. Storage location used by computer memory to store data for usage by an application is ?

Correct Answer is : IndexOutOfRangeException

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon