Copy link:
Copy

What is the output of the short program below? class Program { static String location; static DateTime time; static void Main() { Console.WriteLine(location == null ? "location is null" : location); Console.WriteLine(time == null ? "time is null" : time.ToString()); }}
1/1/0001 12:00:00 AM
location is null1/1/0001 12:00:00 AM
Compilation error
{empty string}

What statements are true for abstract classes in C#?
Abstract classes can inherit no more than two interfaces
Abstract class can contain either abstract or virtual members
Abstract class can't be instantiated
Abstract class can inherit abstract class only
It's impossible to define fields in abstract class

What is the output for the below code snippet?using System;public class Test{ public static void Main() { Console.WriteLine(0 / 0.0 == 0 / 0.0); }}
Compile-time error
Runtime error
True
False

What is the output for the below code snippet?using System.IO;using System;class Program{ static void Main() { int i = 0; i += i++ + i++; Console.WriteLine(i); }}
4
3
2
1
0

What is the output for the below code snippet?using System;using System.Collections.Generic;public class Test{ public static void Main() { Dictionary dic = new Dictionary(); int i = 0; dic["id"] = 5; if (dic.TryGetValue("id", out i)) { Console.WriteLine("id = {0}", i); } }}
id = 5
Runtime error
Nothing will be displayed
Compile-time error
id = 0

What is the output for the below code snippet?using System.IO;using System;class Program{ static void Main() { int? i = null; Console.WriteLine(i ?? Convert.ToInt32(i.HasValue)); }}
null
0
Compile-time error
False
Runtime error

What is the output for the below code snippet?using System;public class Runner{ public static void Main() { Runner r = new Runner(); Console.WriteLine(r); }}
0
Compile-time error
Runtime error
int
Runner

What is the output for the below code snippet?using System.IO;using System;class Program{ static void Main() { object a = 1; object b = 1; if(b == a) { Console.WriteLine("equal"); } else { Console.WriteLine("not equal"); } }}
equal
not equal
Compile-time error

What is the output for the below code snippet?using System;public class Test{ public static void Main() { Method(1, 2); } static void Method(params int[] a) { Console.WriteLine(1); } static void Method(int a, int b) { Console.WriteLine(2); } static void Method(int a, params int[] b) { Console.WriteLine(3); }}
1
2
3
Compile-time error

For the below code snippet:using System; class A { }class B: A { }class Program { static void Main() { A obj = new B(); } }which of the following expressions will return True?
obj.GetType() == typeof(B)
obj is A
obj.GetType() == typeof(A)
obj is B

What is the output for the below code snippet?using System;class Program{ static void Main(string[] args) { Console.WriteLine(Test(1)); } public static int Test(int i) { try { return i; } finally { Console.WriteLine("In finally"); i = 2; } }}
In finally1
1
Compile-time error
In finally2

What is the output for the below code snippet?using System;class Test{ static void Main(string[] args) { Console.WriteLine(Method(1)); } public static int Method(int i) { try { return i; } finally { i = 2; } return 3; }}
2
1
3
Compile-time error

What method definitions contain errors?public class Test{ public void M1(int[] a, int[] b) { } public void M2(int[] a, params int[] b) { } public void M3(params int[] a, int[] b) { } public void M4(params int[] a, params int b) { } }
M1
M2
M3
M4

What is the difference between interface and abstract class?
you cannot change access modifiers in interface
interface can be inherited from 3 and more classes
interfaces names have to start with 'I' prefix
interface can be instantiated
interface mustn't contain delegates declaration

What is the output for the below code snippet?using System.IO;using System;class Program{ static int a = getB(); static int b = 5; static int getB() { return b; } static void Main() { Console.WriteLine(a); }}
null
Compile-time error
5
0

Copy link:
Copy

Authored by:

Tests Created: 2

  • 2 Followers
  • Send message
More Tests By Author:
WC Interview (53 Questions)
107
attempts
Discussion
Your Facebook Friends on WizIQ