C# Test 3

More C# Tests

Question 1: What will be the output of the following program?

public class Program
{
	public static void Main()
	{
		Person per = new Person();
		Console.WriteLine(per.Id); 
	}
}

public class Person
{
	public int Id;
}

Question 2: Which of the following type escapes type checking at compile-time; instead, it resolves type at run time?

Question 3: What will be the output of the following program?

public static void Main()
{
	var x;
	x=100;
	Console.WriteLine(x); 
}

Question 4: Which of the following data type should be used for monetary value?

Question 5: What will be the output of the following program?

public static void Main()
{
    float f = 10.12f;
    long l = 200L;

    Console.WriteLine(f+l);
}

Question 6: What will be the output of the following program?

public static void Main(string[] args)
{
    int i = 2;
	   
 	Console.Write(++i);  
	Console.Write(i++);
	Console.Write(i);  
}

Question 7: A constructor can be _________.

Question 8: Which of the following is the default access modifier of the class members?

Question 9: Which of the following statements is TRUE?

Question 10: What will be the output of the following program?

public static void Main(string[] args)
{
	string str1 = "Hi";
	string str2 = String.Copy(str1);
		
	Console.Write(Object.ReferenceEquals(str1, str2));
}

Question 11: What will be the output of the following program?

for (double d = 1.01D; d < 1.05; d+= 0.01D)
{
    Console.Write("{0}, ", d);
}

Question 12: What will be the output of the following program?

public class Program
{
	public static void Main()
	{
		WorkingDays.Wednesday= 5;
		Console.Write(WeekDays.Wednesday);
	}
}

enum WorkingDays
{
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday
}

Question 13: What will be the output of the following program?

public class Program
{
	public static void Main()
	{
		Console.Write((int)Color.Green);
	}
}
enum Color 
{
    Red,
    Green=0,
    Blue=0
}

Question 14: Which of the following statement is correct bout the structure (struct)?

Question 15: What will be the output of the following program?

public static void Main(string[] args)
{
	Point p;
	p.x=10;
	Console.Write( p.x);
}

struct Point
{
	private int _x;
	public int x{
        get{
            return _x;
        }

        set{
            _x = value;
        }
}

Question 16: Which of the following array declaration is valid?

Question 17: What will be the output of the following program?

HashSet hs = new HashSet(){
    1,1,2,3,3
};

foreach(var val in hs)
    Console.Write(val);

Question 18: What will be the output of the following program?

public static void Main()
{
    int[] arr = {1, 2, 3, 4, 5};
		
    try{
        Console.Write(arr[10]);
    }
	catch(Exception ex){
		Console.WriteLine("Error occurred!");
	}
	catch(IndexOutOfRangeException  ex){
        Console.WriteLine("Index error occurred!");
    }
    catch(NullReferenceException  ex){
        Console.WriteLine("Null error occurred!");
    }
}

Question 19: What will be the output of the following program?

public static void Main()
{
	int[] arr = {1, 2, 3, 4, 5};
	
    try{
        Console.Write(arr[10]);
    }
	finally{
		Console.WriteLine("Error occurred!");
	}
}

Question 20: The finally block is always executed irrespective of whether an exception occurs or not.