100% found this document useful (1 vote)
467 views

C# Question - Answer

The document contains 15 questions related to C# programming concepts. Each question provides multiple choice options to identify errors, predict outputs, or choose true statements about C# features. The questions cover topics like arrays, methods, data types, and the .NET framework.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
467 views

C# Question - Answer

The document contains 15 questions related to C# programming concepts. Each question provides multiple choice options to identify errors, predict outputs, or choose true statements about C# features. The questions cover topics like arrays, methods, data types, and the .NET framework.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 49

Question Text 1.

Predict the output of the following program.


using System;

namespace Arrays_1
{
class Program
{
static void Main(string[] args)
{

int i;
if ((i = 10 / 2) = 0)
Console.WriteLine("Even Number");
else
Console.WriteLine("Odd Number");
Console.Read();
}
}
}

Options

1. It will give an error.


2. It will print Odd Number.
3. It will print
Odd Number
Even Number
4. It will print Even Number.

Correct Answer: -> 1

Question Text 2.
Consider the following code snippet:
using System;
class Break
{

public static void Main(string[] args)


{
const char White ='W';
const char Gray ='G';
char ch;
for (int count = 0; count < 5*2 - 1; count++)
{
ch = White;
for (int j = 2; j < count; j++)
{
if (count % j == 0)
{
ch = Gray;

}
Console.WriteLine(ch);
break;
}
}
Console.ReadLine();
}
}

Identify the output of the preceding code.

Options

1. The output is:


W
G
W
G
W
G
2. Compilation error
3. The loop will run till infinity
4. The output is:
W
G
W
G

Correct Answer: -> 1

Question Text 3.

Consider the following code


using System;

namespace Arrays_1
{
class Program
{
static void Main(string[] args)
{
int[] arrayFirst = { 10, 20, 30, 40, 50 };
int[] arraySecond= {1 , 2, 3, 4, 5};
int[] arraythird= new int[5];
int counter = 0; //Line 1
for (counter = 0; counter < 5; counter++) //Line 2
{
arraythird[counter] = arrayFirst[counter] + array[counter]; //Line 3
}
for (counter = 0; counter < 5; counter++) //Line 4
Console.WriteLine("{0}", arraythird[counter]);
Console.ReadLine();
}
}
}
Identify the error
Options

1. Line 1
2. Line 2
3. Line 3
4. Line 4

Correct Answer: -> 3

Question Text 4.

Consider the following statements:


Statement A: The reference types data types do not maintain the data but they directly contain a
reference to the variables, which are stored in the memory.
Statement B: In the reference types data types, if the value in the memory location is modified by one of
the variables, the change is reflected in the other variables automaatically.
Identify whether the preceding statements are true or false.

Options

1. Both statement A and B are true


2. Statement A is true and B is false
3. Statement A is false and B is true
4. Both statement A and B are false

Correct Answer: -> 1

Question Text 5.

Consider the following code and identify the error.


using System;
namespace Struct
{
struct distance
{
public int feet;
public float inches;
};
struct room
{
public distance Length;
public distance Width;
};
class Program
{
static void Main(string[] args)
{
room r1 = new room();
r1.Length.feet = 10; //Line 1
r1.Length.inches = 8.5F; //Line 2
r1.Width.feet = 10; //Line 3
r1.Width.inches = 6.5; //Line 4
float L = r1.Length.feet + r1.Length.inches / 12;
float W = r1.Width.feet + r1.Width.inches / 12;
Console.WriteLine("The Dining Area is {0}", L * W);
Console.ReadLine();

}
}
}

Options

1. Line 1
2. Line 2
3. Line 3
4. Line 4

Correct Answer: -> 4


*************************************************************************************

Question Text 6.

Identify the output of the following code.


using System;

namespace Const2
{
class Program
{
public int count;
public Program()
{
count = 1;
}
public void inc_count()
{
count++;
}
public int get_count()
{
return count;
}
}
class count_class
{
static void Main(string[] args)
{
Program P1 = new Program();
Program P2 = new Program();
Console.WriteLine("P1= {0}",P1.get_count ());
P1.inc_count();
P2.inc_count();
Console.WriteLine("P2= {0}",P2.get_count ());
Console.ReadLine();

}
}
}
Options

1. P1= 1
P2= 2
2. P1=1
P2=1
3. P1=2
P2=2
4. Compilation error

Correct Answer: -> 1

Question Text 7.

Consider the following code:


using System;
class Watches
{
public static void Main(String[] rags)
{
char Watch_Name;
int Watch_Price;

Console.WriteLine("Enter the name of the watch you want to buy");


Watch_Name = Convert.ToChar(Console.ReadLine());

Console.WriteLine("Enter the price within which you want to buy the watch");
Watch_Price=Convert.ToInt32(Console.ReadLine());
}
}

The preceding code when executed shows the error. Identify the error in the preceding code.
Options

1. The variable Watch_Price needs to be string variable.


2. The variable Watch_Name needs to be string variable.
3. The naming of variable Watch_Name is incorrect.
4. The naming of variable Watch_Price is incorrect.

Correct Answer: -> 2

Question Text 8.

consider the following code.


using System;
namespace Arrays1
{
class Program
{
static void Main(string[] args)
{
double[] nums ={ 10.1, 10.2, 11.3, 12.5, 13.4 };
double result = 0.0;
int i;
for (i = 0; i < 5; i++)

result = result + nums[i];


Console.WriteLine("The result is {0}", result / 5);
Console.ReadLine();
}
}
}
Predict the Output of the preceding code.

Options

1. The result is 11.5


2. The result is 12.5
3. Compilation error
4. The result is 13.5

Correct Answer: -> 1

Question Text 9.

Predict the output of the following code:


using System;
class Weight
{
public static void Main(string[] args)
{
Weight K1 = new Weight();
double kgs;
kgs = K1.lbstokg(182);
Console.WriteLine("Your weight in Kilograms is: {0}", kgs);
Console.ReadLine();
}
double lbstokg(double pounds)
{
double kilograms = 0.453592 * pounds;
return kilograms;
}
}

Options

1. Your weight in Kilograms is: 82.553741


2. Your weight in Kilograms is: 82
3. Your weight in Kilograms is: 82.55
4. Your weight in Kilograms is: 82.5537

Correct Answer: -> 1


Question Text 10.

Consider the following code:


using System;
class Vegetables
{

public static void Main(string[] args)


{
string Vegetable_Name;
int Vegetable_Amount;

Console.WriteLine("Enter the name of the vegetable you want to buy");


Vegetable_Name = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter the amount of the vegetable you want to buy");


Vegetable_Amount = Convert.ToInt32(Console.ReadLine());
Console.ReadLine();
}
}
The preceding code when executed shows the error. Identify the error form the preceding code and
rectify it.

Options

1. The error is in the conversion of the variable Vegetable_Name.


To convert the string variable the programmer should write the following statement:
Vegetable_Name = Console.Readline();
2. The error is in the conversion of the variable Vegetable_Amount.
To convert the int variable the programmer should write the following statement:
Vegetable_Name = Convert.ToInt32(Console.Readline());
3. The error is in the conversion of the variable Vegetable_Name.
To convert the string variable the programmer should write the following statement:
Vegetable_Name = Convert.ToChar(Console.Readline());
4. The error is in the conversion of the variable Vegetable_Name.
To convert the string variable the programmer should write the following statement:
Vegetable_Name = Convert.ToDouble(Console.Readline());
Correct Answer: -> 1

*************************************************************************************

Question Text 11.

Predict the out put of the following program.

using System;

class AddNumbers
{

class Calculator
{
void AddOne(int var)
{
var++;
++var;
var++;
}
public static void Main()
{
Calculator obj = new Calculator();
int number = 6;
obj.AddOne(number);
Console.WriteLine(number);
Console.Read();
}
}
}

Options

1. 6
2. 8
3. 9
4. 7

Correct Answer: -> 1


*************************************************************************************

Question Text 12.

Identify the component of the .NET Framework which allows the execution of code across different
platforms by translating code into Intermediate Language.

Options

1. Common Language Runtime


2. .NET Framework Base Classes
3. The user and program interfaces
4. Web Forms

Correct Answer: -> 1

Question Text 13.

Consider the following code:


using System;

namespace Arrays_1
{
class Program
{
static void Main(string[] args)
{
int[] arrayFirst = { 10, 20, 30, 40, 50 };
int[] arraySecond= {1, 2, 3, 4, 5};
int[] arraythird= new int[5];
int counter = 0;
for (counter = 0; counter < 5; counter++)
{
arraythird[counter] = arrayFirst[counter] +
arraySecond[counter];
}
for (counter = 0; counter < 5; counter++)
Console.WriteLine("{0}", arraythird[counter]);
Console.ReadLine();
}
}
}
Predict the output of the preceding code.

Options

1. 11
22
33
44
55
2. 10
20
30
40
50
3. 1
2
3
4
5
4. Compilation error

Correct Answer: -> 1

Question Text 14.


Identify the line, which will generate an error in the following program.
using System;

namespace Arrays_1
{
class Program
{
static void Main(string[] args)
{
double[] nums; //Line 1
double result = 0.0; //Line 2
int i;
for (i = 0; i < 5; i++) //Line 3

result = result + nums[i]; //Line 4


Console.WriteLine("The result is {0}", result / 5);
}
}
}

Options

1. Line 4
2. Line 2
3. Line 3
4. Line 1

Correct Answer: -> 1

Question Text 15.

Consider the following code and predict the output.


using System;
namespace Fun_1
{
class Program
{
public int Min(int num1, int num2)
{
if (num1 > num2)
{
return num1;
}
else
{
return num2;
}
}
public Boolean Min(float num1, float num2)
{
if (num1 > num2)
return true;
else
return false;
}
class test
{
static void Main(string[] args)
{
Program p1 = new Program();
Console.WriteLine("{0}", p1.Min(10, 10));
Console.WriteLine("{0}", p1.Min(20, 2));
Console.ReadLine();
}
}
}
}

Options

1. It will print
10
20
2. It will print
10
3. It will print
20
10
4. Compilation error
Correct Answer: -> 1

Question Text 16.

Determine the output of the following code:

class Base
{
~Base()
{
Console.WriteLine("Destroying Base");
}
}
class Derived : Base
{
~Derived()
{
Console.WriteLine("Destroying Derived");
}
}

class Test
{
static int Main(string[] args)
{
Base obj = new Derived();
Console.Read();
return 0;
}
}

Options

1. It will print:
Destroying Base
Destroying Derived
2. It will print:
Destroying Derived
Destroying Base
3. It will print:
Destroying Base
4. It will print:
Destroying Derived

Correct Answer: -> 2


***********************************************************************************

Question Text 17.

Predict the output of the following program.

class AddNumbers
{
int result;
AddNumbers()
{
result = 0;
}
public void Divide(int number1, int number2)
{
try
{
result = number1 / number2;

}
catch (DivideByZeroException e)
{
Console.WriteLine("Exception caught.{0} ", e);
}
finally
{
Console.WriteLine("Result is {0}", result);
}
}
public static void Main(string[] args)
{
AddNumbers Division = new AddNumbers();
Division.Divide(10, 5);
Console.ReadLine();
}
}

Options

1. Program will print "Result is 2".


2. Program contains a Syntax error.
3. Program contains a Logical error.
4. Program will throw Zero division exception.

Correct Answer: -> 1

Question Text 18.

Identify the type of error in the following code snippet.

static void Main()


{
int i=1;
while(i<=10)
Console.WriteLine ("{0}",i);
i++;
}

Options

1. Syntax error
2. Run-Time error
3. Logical error
4. Zero division error

Correct Answer: -> 3


Question Text 19.

Determine the output of the following code:


using System;
class Base
{
public Base()
{
Console.WriteLine("Constructor of Base");
}
}
class Derived : Base
{
public Derived()
{
Console.WriteLine("Constructor of Derived");
}
}
class BaseDerived : Derived
{
public BaseDerived()
{
Console.WriteLine("Constructor of BaseDerived");
}
}

class Test
{
static int Main(string[] args)
{
Derived obj = new BaseDerived();
Console.Read();
return 0;
}
}

Options

1. Constructor of Base
Constructor of Derived
Constructor of BaseDerived
2. Constructor of BaseDerived
Constructor of Derived
Constructor of Base
3. Constructor of Base
Constructor of BaseDerived
Constructor of Derived
4. Constructor of BaseDerived
Constructor of Base
Constructor of Derived

Correct Answer: -> 1

*************************************************************************************
Question Text 20.

Predict the output of the following program.

struct NumberCount
{
public int i;
public NumberCount(int initval)
{
this.i = initval;
}
public static NumberCount operator ++(NumberCount arg)
{
arg.i++;
return arg;
}
}
class TestClass
{
static void Main(string[] args)
{

NumberCount Count1 = new NumberCount(1);

NumberCount Count2 = Count1++;


Console.WriteLine(Count1.i);
Console.WriteLine(Count2.i);
Count2 = ++Count1;

Console.WriteLine(Count1.i);
Console.WriteLine(Count2.i);
Console.ReadLine();
}
}

Options

1. It will print:
1
2
3
3
2. It will print:
3
3
1
2
3. It will print:
2
1
3
3
4. It will print:
2
1
3
2

Correct Answer: -> 3


Question Text 21.

Predict the output of the following program.

class Program
{
String name;
int age;
public Program(int i)
{
age = i;
}
static void Main(string[] args)
{
Program p = new Program();
Console.Write("Enter name: ");
p.age=Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Name: {0}",p.name);
Console.WriteLine("Age: {0}", p.age);
}
}

Options

1. It will print the name and age entered by the user in the same line.
2. It will print the name and age entered by the user in the different lines.
3. It will print the name as entered by the user but the age will be printed as 0.
4. It will give an error.

Correct Answer: -> 4

Question Text 22.

Analyse the following code and choose the most appropriate option.
using System;
using System.Threading;
class AddNumbers
{

public static void ChildThreadCall1()


{
Console.WriteLine("Child Thread - 1");
}
public static void ChildThreadCall2()
{
Console.WriteLine("Child Thread - 2");
}
public static void Main()
{
ThreadStart Child1 = new ThreadStart(ChildThreadCall1);
ThreadStart Child2 = new ThreadStart(ChildThreadCall2);
Console.WriteLine("Main - Creating Child threads");

Thread Thread1 = new Thread(Child1);


Thread Thread2 = new Thread(Child2);

Thread1.Priority = ThreadPriority.Lowest ;
Thread2.Priority = ThreadPriority.Highest ;

Thread1.Start();
Thread2.Start();
Console.Read();
}

Options

1. The program will run both the threads.


2. The program will run only the Thread1 thread.
3. The program will run only the Thread2 thread.
4. The program will throw an error.

Correct Answer: -> 1


Question Text 23.

Analyze the following code and select the most appropriate option.

public delegate void TimeToRise();


private event TimeToRise RingAlarm;
Student PD= new Student();
RingAlarm = new TimeToRise(PD.WakeUp);

Options

1. The Student class subscribes to the method named WakeUp.


2. The RingAlarm event is initialized with the WakeUp method.
3. The Student class subscribes to the event named TimeToRise.
4. The TimeToRise class subscribes to the event named Student.

Correct Answer: -> 3

Question Text 24.

Sam has created the following program to read the contents of a file. During the execution of the
program he found that only a single character is repeatedly displayed on the console and the program
runs into an infinite loop. Find the possible cause of the error.

using System;
using System.IO;

class Program
{
static int Main(string[] args)
{
char ch;
FileStream fs = new FileStream(@"c:\preeti\myfile.txt", FileMode.Open , FileAccess.Read );
StreamReader sr = new StreamReader(fs);
ch=Convert.ToChar(sr.Read());
while (ch != -1)
Console.Write("{0}",ch);
Console.Read();
return 0;
}
}

Options

1. Text file cannot be read through the Read function.


2. The end of file should be checked by writing (ch!=null).
3. The while loop is causing the error. It should contain the read statement also.
4. The ReadLine() function should be used in place of Read() function.

Correct Answer: -> 3

Question Text 25.

Analyze the following code and predict the output.

using System;
using System.Timers;

class myApp
{
public static void Main()
{
Timer myTimer = new Timer();
myTimer.Elapsed += new ElapsedEventHandler( DisplayTimeEvent );
myTimer.Interval = 1000;
myTimer.Start();

while ( Console.Read() != 'q' )


{
;
}
}

public static void DisplayTimeEvent( object source, ElapsedEventArgs e )


{
Console.Write("\r{0}", Convert.ToString(DateTime.Now).Substring(9,8));
}
}

Options

1. It will display a digital clock (running) on the console.


2. It will display the current date on the console.
3. It will display the current time on the console.
4. It will display an error.

Correct Answer: -> 1


*************************************************************************************

Question Text 26.

A programmer is developing software for a recruitment company. He is following the OOPS concept. He
has created a general class named Candidate. He is using this class as a super class only. He is not
creating any object of this class.
Which type of class is the candidate class?

Options

1. Subclass
2. Super Class
3. Class
4. Abstract Class

Correct Answer: -> 4


Question Text 27.

Analyse the following program and predict the output.

using System;
public class MyClass
{
class testing
{
public int Division(int a, int b)
{
return a/b;
}
public float Division(int a, int b)
{
float x,y;
x=a;y=b;
return x / y;
}

public static void Main()


{
testing t=new testing();
Console.WriteLine(t.Division(10,2));
Console.Write(t.Division(5 /2));
Console.Read();
}
}
}

Options

1. It will print
5
2.5
2. It will print
2.5
5
3. It will print
5 2.5
4. It will give an error.

Correct Answer: -> 4

Question Text 28.

Analyze the following program and choose the most appropriate answer.

class AddNumbers
{
public static void Adding_Numbers(int number1, int number2)
{
try
{
int res = number1 / number2;
Console.WriteLine(res);
}
catch (DivideByZeroException e)
{
Console.WriteLine("Exception caught. {0} ", e);
}
}
public static void Main()
{
AddNumbers.Adding_Numbers(10, 0);
Console.ReadLine();
}
}

Options

1. Symantec Error
2. Syntax error
3. Logical error
4. Run-Time error
Correct Answer: -> 4

Question Text 29.

Sam is destroying a thread in his program by using the Thread.Abort() method. Identify the mechanism
used by the CLR to detroy the thread when the Thread.Abort() method is used.

Options

1. The CLR destroys a thread by calling Sleep method for infinite time.
2. The CLR destroys a thread by throwing an exception.
3. The CLR destroys a thread by calling the Suspend method.
4. The CLR destroys a thread by calling the Resume method.

Correct Answer: -> 2

Question Text 30.

A programmer is using the StreamReader class in his program. He needs a method, which returns the
next available character but does not consume it. Identify the method, which could be used for the
purpose.

Options

1. Close
2. Read
3. Peek
4. Seek

Correct Answer: -> 3


Question Text 31.

A programmer needs to make a thread wait for some specified condition to be satisfied by calling the
Wait() method. Which method will be used to notify the thread about the condition?

Options

1. Pulse() method
2. Start() method
3. Resume() method
4. Suspend() method

Correct Answer: -> 1

Question Text 32.

Identify the error in the following code snippet.

public delegate int TimeToRise();


private event TimeToRise RingAlarm;
Student PD= new Student();
RingAlarm = new TimeToRise(PD.WakeUp);

Options

1. The event should be declared as Public.


2. The delegate should be declared as Private.
3. The delegate and the event both should either be public or private.
4. The delegate that subscribe to an event must be declared as Void.

Correct Answer: -> 4

Question Text 33.


Find out the error in the following program.
using System;
using System.Threading;
class AddNumbers
{

public static void ChildThreadCall()


{
Console.WriteLine("Testing threads");
}
public static void Main()
{
ThreadStart ChildRef = new ThreadStart(ChildThreadCall);

Console.WriteLine("Main - Creating Child thread");

Thread ChildThread = new Thread(ChildRef);


ChildThread.Start();

ChildThread.Abort();
ChildThread.Start();
Console.ReadLine();
}
}

Options

1. The ChildThreadCall() method should be declared as Private.


2. The Start() method should be called after the Sleep() method.
3. The Abort() method should not be called after the Start() method.
4. The start() method should not be called after the Abort() method.

Correct Answer: -> 4


*************************************************************************************
Question Text 34.

To use a variable num for storing a numeric value without any fractional part, the variable num must be
declared and it should be of the type:
Options

1. char
2. numeric
3. float
4. positive

Correct Answer: -> 2


*************************************************************************************

Question Text 35.

The complexity of a program can be reduced by creating:

Options

1. Statements
2. Functions
3. Structured programs
4. Variables

Correct Answer: -> 2

Question Text 36.

Give the output of the following:


public class abc
{
public void Main(string[] args)
{
System.Console.WriteLine("hello");
}
}

Options
1. will give the output "hello".
2. will give error.
3. will read a string "hello".
4. compile successfully but no output is displayed.

Correct Answer: -> 2

Question Text 37.

Give the output of the following program:

using System;
class demo
{
public static void Main(string[]args)
{
bool compare;
string s1,s2;
s1 = "Welcome";
s2 = "NIITians";
compare=(s1=="Hello")^(s2=="NIITians");
Console.WriteLine(compare.ToString());
}
}

Options

1. The message False will be displayed because both the expression are true.
2. The message True will be displayed because both the expressions are false.
3. The message False will be displayed because both the expressions are false.
4. The message True will be displayed because one expression is false.

Correct Answer: -> 4

Question Text 38.


Which of the following code snippet will be used to print a Fibonacci series unto 100 when a=b=1;

Options

1. Console.WriteLine("{0}",a);
while(b < 100)
{
Console.WriteLine( b);
b=b+a;
a=b-a;
}
2. Console.WriteLine("{0}",a);
while(b<100)
{
Console.WriteLine(b);
b = b++;
a = a-b;
}
3. Console.WriteLine("{0}",a);
while(b>100)
{
Console.WriteLine( b);
b=b+a;
a=b-a;
}
4. Console.WriteLine("{0}",a);
while(b<100)
{
Console.WriteLine( b);
b=b+a;
a=a--;
}

Correct Answer: -> 1

Question Text 39.

Which of the following is the correct structure to define a method:


Options

1. < return type > < access specifier > < method name > (parameter list)
{
method body
}
2. < return type > < access specifier > < method name > [parameter list]
{
method body
}
3. < access specifier > < return type > < method name > { parameter list}
{
Method body
}
4. < access specifier > < return type > < method name > (parameter list)
{
Method body
}

Correct Answer: -> 4


*************************************************************************************

Question Text 40.

Give the output of the following program:


using System;
sealed class a
{
public abstract void one()
{
Console.WriteLine("you are in sealed class");
}
}
class inherit_demo1
{
public static void Main()
{
a obj = new a();
obj.one();
}
}

Options

1. It will display a message "you are in sealed class".


2. No message will be displayed.
3. The program will give error because a.one() can't be declared with a body since it is marked
abstract.
4. Sealed is an unrecognized keyword.

Correct Answer: -> 3

Question Text 41.

Consider the following code snippet:


abstract class a
{
public abstract void show();
}
Which of the following option will define the implementation of method show() in class b?

Options
1. class b:a
{
public override void show()
{
Console.WriteLine("you are in class b");
}
}
2. class b:a
{
public void show()
{
a:s();
Console.WriteLine("you are in class b");
}
3. class b
{
public void show()
{
a obj = new a();
obj.show();
}
4. class b:a
{
private override void show()
{
Console.WriteLine("you are in class b");
}

Correct Answer: -> 1

Question Text 42.

Mr. Joe wants to store the details of all the employees.


He does so using the following class definition:
class emp
{
string e-name;
int e-id;
void accept-details()
{}
void display-details()
{}
}
However, the above class definition is wrong. Give the correct class definition.

Options

1. class emp
{
{
string name;
int eid;
void accept_details[]
{}
void display_details()
{}
}
}
2. class emp
{
{
void accept_details()
{
string name;
int eid;
}
void display-details()
{
string name;
int eid;
}
}
}
3. class emp
{
string e_name;
int e_id;
void accept_details()
{}
void display_details()
{}
}
4. class emp
{
void accept_details()
{
string name;
int eid;
}
void display_details()
{
string name;
int eid;
}
}

Correct Answer: -> 3


*************************************************************************************
Question Text 43.

Give the output of the following program;


using System;
namespace s
{
class enum_demo
{
enum e{jan,feb,mar,dec};
static void Main(string[] args)
{
int m1=(int)e.dec;
Console.WriteLine("Dec={0}",m1);
Console.ReadLine();
}
}
}

Options

1. Dec=12
2. Dec = 4
3. Dec = 3
4. Dec = 0

Correct Answer: -> 3

Question Text 44.

Give the output of the following program:


using System;
namespace OperatorOverload
{
struct emp
{
public int id;
public emp(int i)
{
this.id=i;
}
static public emp operator --(emp e)
{
e.id--;
return e;
}
}

class over_demo
{
static void Main(string[] args)
{
emp e1=new emp(2);
emp e2 = --e1;
Console.WriteLine(e1.id);
Console.WriteLine(e2.id);
e2=e1--;
Console.WriteLine(e1.id);
Console.WriteLine(e1.id);
Console.ReadLine();
}
}
}

Options

1. 1
2
0
0
2. 1
1
0
0
3. 2
1
0
0
4. 2
2
0
0

Correct Answer: -> 2

Question Text 45.

Give the output of the following program:

using System;
namespace s
{
class enum_demo
{
enum e{jan,feb,mar,dec};
static void Main(string[] args)
{
string m1=(string)e.dec;
Console.WriteLine("{0}",m1);
Console.ReadLine();
}
}
}

Options

1. Dec
2. 3
3. It will display the message, Can't convert type 's.enum_demo.e' to string.
4. The program will compile but no message will be displayed.

Correct Answer: -> 3

Question Text 46.


Which of the following code snippet is syntactically correct according to the rules applied for declaring
the prefix and postfix notations for operator overloading?

Options

1. internal static over operator++ (over x)


{}
2. static static over operator++ (over x)
{}
3. private static over operator++ (over x)
{}
4. public static over operator++ (over x)
{}

Correct Answer: -> 4


*************************************************************************************
Question Text 47.

Give the output of the following code:


using System;
using System.IO;
namespace dele
{
public class dele_demo
{
public delegate void PData(String s);

public static void WC (String str)


{
Console.WriteLine("{0} Console",str);
}
public static void DData(PData PMethod)
{
PMethod("This should go to the");
}
public static void Main()
{
WC MlDelegate = new WC(PData);
DData(MlDelegate);
}
}
}
Options

1. It will compile successfully but generate a runtime error.


2. It will display "This should go to the".
3. It will display "This should go to the console".
4. It will give compilation error.

Correct Answer: -> 4

Question Text 48.

Choose the correct code to define the event named 'ehello' that invokes a delegate named 'hello'

Options

1. public delegate hello();


private event delegate ehello();
2. public delegate void hello();
private event delegate ehello();
3. public delegate hello();
private event ehello hello();
4. public delegate void hello();
private event hello ehello();

Correct Answer: -> 4

Question Text 49.

Which of the following statement is correct in context to static constructor?

Options

1. Static constructors are used only by static classes to initialize their variables.
2. Static constructors are used for initializing both static and non-static variables of a class.
3. The static constructors have an implicit public access.
4. The static constructors have an implicit private access.

Correct Answer: -> 4

Question Text 50.

Give the output of the following program:


using System;
namespace o
{
class life_demo
{
~life_demo()
{
Console.WriteLine("you are in constructor");
}
life_demo()
{
Console.WriteLine("you are in destructor");
}
public static void Main(string[] args)
{
life_demo obj = new life_demo();
}
}
}

Options

1. It will display:
destructor can not be defined before constructor
2. It will display:
you are in destructor
3. It will display:
you are in constructor
4. It will give compilation error.

Correct Answer: -> 2


*************************************************************************************
Question Text 51.

System.NullReferenceException exception class handles :


Options
1. I/O errors.
2. errors generated when method refers to an array element.
3. errors generated during the process of dereferencing a null object.
4. memory allocation to the application errors.

Correct Answer: -> 3

Question Text 52.

The following code was written to write in a file named "abc.txt". The code is not performing the desired
task. Identify the code snippet that will help perform the desired task.

using System;
using System.IO;
class file_demo
{
public void accept()
{
FileStream f = new FileStream("abc.txt");
StreamWriter s = new StreamWriter(f);
Console.WriteLine("Enter the String:");
string s1 = Console.ReadLine();
s.Write(s1);
s.Flush();
s.Close();
f.Close();
}
public static void Main(string[] args)
{
file_demo obj = new file_demo();
obj.accept();
}
}
Options

1. FileStream f = new FileStream("abc.txt",FileMode.Append,FileMode.Write);


StreamWriter s = new StreamWriter(f);
Console.WriteLine("Enter the String:");
string s1 = Console.WriteLine();
2. FileWriteStream f = new FileWriteStream("abc.txt",FileMode.Append,FileMode.Write);
StreamWriter s = new StreamWriter(f);
Console.WriteLine("Enter the String:");
string s1 = Console.WriteLine();
3. FileWriteStream f = new FileWriteStream("abc.txt",FileMode.Append,FileMode.Write);
StreamWriter s = new StreamWriter(f);
Console.WriteLine("Enter the String:");
string s1 = Console.ReadLine();
4. FileStream f = new FileStream("abc.txt",FileMode.Append,FileMode.Write);
StreamWriter s = new StreamWriter(f);
Console.WriteLine("Enter the String:");
string s1 = Console.ReadLine();

Correct Answer: -> 4

Question Text 53.

What is the purpose of the following line of code: [DllImport(.kernel32.dll)]

Options

1. It will call the unmanaged code defined in kernel from managed C# environment.
2. It will call the unmanaged code defined in Dll from managed C# environment.
3. It will call and import the unmanaged code residing in kernel to Dll.
4. It will import the unmanaged code residing in Dll to kernel.

Correct Answer: -> 2

Question Text 54.

Consider the following statement:


Thread 'a', Thread 'b', and Thread 'c' are accessing variable ' x' simultaneously. Thread 'b' wants to assign
value 10 to the variable x.
Identify the situation being referred to in the above statement.

Options

1. DeadLock
2. Race condition
3. Lock starvation
4. Wait

Correct Answer: -> 2

Question Text 55.

Consider the following code that is written to abort a thread but is not able to abort the child
thread,why? Give reason.
using System;
using System.Threading;
namespace ThreadSample
{
class Thred_demo1
{
public static void Child()
{
try
{
Console.WriteLine("Child thread started");
Console.WriteLine
("Child thread - counting to 10");
for (int i = 0; i < 10; i++)
{
Thread.Sleep(500);
Console.Write("{0}...", i);
}
Console.WriteLine("Child thread finished");
}
catch (ThreadAbortException e)
{
Console.WriteLine("Exception"+e);
}
finally
{
Console.WriteLine
("Child thread -Unable to catch the exception.");
}
}
public static void Main()
{
ThreadStart ChildRef = new ThreadStart(Child);
Console.WriteLine("Main - Creating Child thread");
Thread ChildThread = new Thread(ChildRef);
ChildThread.Start();
Console.WriteLine("Main - Sleeping for 2 seconds");
Thread.Sleep(2000);
Console.WriteLine("\nMain - Aborting Child thread");
Console.ReadLine();
}
}
}

Options

1. The program will give syntactical error.


2. The Main() function should have the following definition
public static void Main()
{
ThreadStart ChildRef = new ThreadStart(Child);
Console.WriteLine("Main - Creating Child thread");
Thread ChildThread = new Thread(ChildRef);
ChildThread.Start();
Console.WriteLine("Main - Sleeping for 2 seconds");
Thread.Sleep(2000);
Console.WriteLine("\nMain - Aborting Child thread");
ChildThread.Abort();
Console.ReadLine();
}
}
3. The Main() function should have the following definition
public static void Main()
{
ThreadStart ChildRef = new ThreadStart(Child);
Console.WriteLine("Main - Creating Child thread");
Thread ChildThread = new Thread(ChildRef);
Console.WriteLine("\nMain - Aborting Child thread");
ChildThread.Abort();
Console.ReadLine();
}
}
4. The Main function should have the following definition
public static void Main()
{
ThreadStart ChildRef = new ThreadStart(Child);
Console.WriteLine("Main - Creating Child thread");
Thread ChildThread = new Thread(ChildRef);
ChildThread.Start();
Console.WriteLine("Main - Sleeping for 2 seconds");
Thread.Sleep(2000);
Console.WriteLine("\nMain - Aborting Child thread");
Console.ReadLine();
}
}
}

Correct Answer: -> 2

You might also like