[go: up one dir, main page]

0% found this document useful (0 votes)
137 views114 pages

OOP - Tieng Anh

The document contains a code snippet and multiple choice questions related to C# concepts like inheritance, polymorphism, constructors, destructors, etc. The code outputs the sum of variables i and j as 2, 10, 12. The questions test understanding of C# features like inheritance accessibility, method overloading, operator overloading, static constructors, and more. Key concepts covered are inheritance, polymorphism, encapsulation, constructors, destructors, and operator overloading in C#.

Uploaded by

Vo Hoai Nam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
137 views114 pages

OOP - Tieng Anh

The document contains a code snippet and multiple choice questions related to C# concepts like inheritance, polymorphism, constructors, destructors, etc. The code outputs the sum of variables i and j as 2, 10, 12. The questions test understanding of C# features like inheritance accessibility, method overloading, operator overloading, static constructors, and more. Key concepts covered are inheritance, polymorphism, encapsulation, constructors, destructors, and operator overloading in C#.

Uploaded by

Vo Hoai Nam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 114

What will be the output for the given set of code?

using System;
namespace ConsoleApplication4
{
abstract class A
{
public int i;
public abstract void display();
}
class B : A
{
public int j;
public int sum;
public override void display()
{
sum = i + j;
Console.WriteLine(+i + "\n" + +j);
Console.WriteLine("sum is:" + sum);
}
}
class Program
{
static void Main(string[] args)
{
A obj = new B();
obj.i = 2;
B obj1 = new B();
obj1.j = 10;
obj.display();
Console.ReadLine();
}
}
}
A. 2, 10 12
B. 0, 10 10
C. 2, 0 2
D. 0, 0 0
Explanation:
Abstract method implementation is processed in subclass B. Also the object obj of
abstract class A initializes value of i as 2. The object of class B also initializes value of j
as 10. Since, the method display() is called using object of class A which is obj and hence
i = 2 whereas j = 0 . So, sum = 2. Output: 2 0 sum is 2

Which keyword is used to refer baseclass constructor to subclass constructor?


A. this
B. static

1
C. base
D. extend

Choose the correct output for given set of code?


class Program
{
enum per
{
a, b, c, d,
}
static void Main(string[] args)
{
per.a = 10;
Console.WriteLine(per.b);
}
}
A. 11
B. 1
C. 2
D. compile time error

In inheritance concept, which of the following members of base class are accessible to
derived class members?
A. static
B. protected
C. private
D. shared

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 derivedclass : baseclass
{
int a = 10;
public void math()
{
/* add code here */
}
2
}
A. Console.WriteLine( a + " " + this.a);
B. Console.WriteLine( base.a + " " + a);
C. Console.WriteLine(a + " " + base.a);
D. Console.WriteLine(baseclass.a + " " + a);

What will be the output of the given code snippet?


using System;

interface calc
{
void cal(int i);
}
class displayA : calc
{
public int x;
public void cal(int i)
{
x = i * i;
}
}
class displayB : calc
{
public int x;
public void cal(int i)
{
x = i / i;
}
}
class Program
{
public static void Main(string[] args)
{
displayA arr1 = new displayA();
displayB arr2 = new displayB();
arr1.x = 0;
arr2.x = 0;
arr1.cal(2);
arr2.cal(2);
Console.WriteLine(arr1.x + " " + arr2.x);
Console.ReadLine();
}
}
A. 0 0
B. 2 2
C. 4 1
D. 1 4
Explanation:

3
class displayA executes the interface calculate by doubling the value of item. Similarly
class displayB implements the interface by dividing item by item. So, variable x of class
displayA stores 4 and variable x of class displayB stores 1. Output: 4, 1

Which keyword is used for correct implementation of an interface in C#?


A. interface
B. Interface
C. intf
D. Intf

Correct way to define operator method or to perform operator overloading is?


A. public static op(arglist) { }
B. public static retval op(arglist) { }
C. public static retval operator op(arglist) { }
D. All of the mentioned

What would be output for the set of code?


using System;
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)
{

4
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();
}
}
A. 4, 3.5
B. 8, 0
C. 7.5, 8
D. 8, 7

What will be the output for the given set of code?


using System;
class A
{
public int i;
public void display()
{
Console.WriteLine(i);
}
}
class B : A
{
public int j;
public void display()
{
Console.WriteLine(j);
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B();
obj.i = 1;
obj.j = 2;
obj.display();
Console.ReadLine();
}
}

A. 0
B. 2
C. 1
D. Compile time error
Explanation:
5
When method display() is called using objects of class B. The method display() for class
B is called instead of class A as class B is inherited by class A. Output: 2

Select the sequence of execution of function f1(), f2() and f3() in C# code?
class BaseClass
{
public void f1() { }
public virtual void f2() { }
public virtual void f3() { }
}
class DerivedClass : BaseClass
{
new public void f1() { }
public override void f2() { }
public new void f3() { }
}
class Program
{
static void Main(string[] args)
{
BaseClass b = new DerivedClass();
b.f1();
b.f2();
b.f3();
}
}
A. f1() of derived class get executed f2() of derived class get executed f3() of base class
get executed
B. f1() of base class get executed f2() of derived class get executed f3() of base class get
executed
C. f1() of base class get executed f2() of derived class get executed f3() of derived class
get executed
D. f1() of derived class get executed f2() of base class get executed f3() of base class
get executed

What will be the correct output for the given code snippet?
using System;
class maths
{
public int fact(int n)
{
int result;
if (n == 1)
return 1;
result = fact(n - 1) * n;
return result;
}
}

6
class Output
{
static void Main(string[] args)
{
maths obj = new maths();
Console.WriteLine(obj.fact(4) * obj.fact(2));
}
}
A. 64
B. 60
C. 120
D. 48
Explanation:
4! = 4*3*2*1 & 2! = 2*1. So, 24*2 = 48. Output: 48

The correct way to define a variable of type struct abc among the following is?
struct abc
{
public string name;
protected internal int age;
private float sal;
}
A. abc e = new abc();
B. abc();
C. abc e; e = new abc;
D. abc e = new abc;

Can the method add() be overloaded in the following ways in C#?


public int add() { }
public float add() { }
A. True
B. False
C. None of the mentioned.
D. None of the Above
Explanation:

7
C# provides feature of method overloading which means methods with same name but
different types and arguments.

Which of the following statements is correct about constructors in C#?


A. A constructor cannot be declared as private
B. A constructor cannot be overloaded
C. A constructor can be a static constructor
D. None of the mentioned
Explanation:
Static constructor is a constructor which can be called before any object of class is
created or any static method is invoked.Static constructor is implicitly called by .NET
CLR.

Select wrong statement about destructor in C#?


A. A class can have one destructor only
B. Destructors cannot be inherited or overloaded
C. Destructors can have modifiers or parameters
D. All of above mentioned

Output from following set of code ?


using System;
class sample
{
int i;
double k;
public sample(int ii, double kk)
{
i = ii;
k = kk;
double j = (i) + (k);
Console.WriteLine(j);
}
~sample()
{
double j = i - k;
Console.WriteLine(j);
}
}
class Program

8
{
static void Main(string[] args)
{
sample s = new sample(8, 2.5);
Console.ReadLine();
}
}

A. 0 0
B. 10.5 0
C. Compile time error
D. 10.5 5.5
Explanation:
First constructor sample is called and hence then destructor ~sample is evaluated.
Output: 10.5, 5.5

Which of following statements about objects in C# is correct?


A. Everything you use in C# is an object, including Windows Forms and controls
B. Objects have methods and events that allow them to perform actions
C. All objects created from a class will occupy equal number of bytes in memory
D. All of the mentioned

"A mechanism that binds together code and data in manipulates, and keeps both safe
from outside interference and misuse. In short it isolates a particular code and data
from all other codes and data. A well-defined interface controls the access to that
particular code and data."
A. Abstraction
B. Polymorphism
C. Inheritance
D. Encapsulation

What is the output for the following set of code :


static void Main(string[] args)
{
int i = 10;
9
double d = 35.78;
fun(i);
fun(d);
Console.ReadLine();
}
static void fun(double d)
{
Console.WriteLine(d);
}
A. 35.78 10
B. 10 35.00
C. 10 35.78
D. None of the mentioned
Explanation:
int datatype is sub datatype of double. Hence, when first part of func() is executed it is
integer part and hence when second part is executed it is double. Output: 10 35.78

How many values does a function return?


A. 0
B. 2
C. 1
D. any number of values

Select the wrong statement about ref keyword in C#?


A. References can be called recursively.
B. The ref keyword causes arguments to be passed by reference.
C. When ref are used, any changes made to parameters in method will be reflected in
variable when control is passed back to calling method.
D. All of above mentioned.

Select correct differences between = and == in C#.


A. == operator is used to assign values from one variable to another variable = operator
is used to compare value between two variables

10
B. = operator is used to assign values from one variable to another variable == operator
is used to compare value between two variables
C. No difference between both operators
D. None of the mentioned

The partial class allows ________


Implementation of single class in multiple .cs files.
Declaration of multiple classes in a single .cs file.
Implementation of multiple interfaces to single class.
Multiple class inheritance.

What will be the output of the following program?


static void Main(string[] args)
{
int i;
Console.WriteLine(i);
}
Random value
0
Runtime error
Compile-time error

What will be the output of the following program?


public static void Main()
{
int k;
display(k);
}

static void display(int val = 0)


{
Console.Write(val);
}
null
0
Compile-time error

11
Runtime error

Which of the following keyword is used to declare a variable whose type will be
automatically determined by the compiler?
dynamic
var
this
null

A constructor in a class can have a return type.


True
False

What will be the output of the following program?


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

public class Person


{
public int Id;
}
""
0
Compile-time error
Runtime error

A constructor can be ______.


public
private
12
protected
internal

Which of the following is the default access modifier of the class members?
public
private
internal
protected internal

interface intfA: one, two, three


{}
Which of the following statements are true for the above code?
a) one, two, three must be classes.
c) one, two, three can be classes or interfaces.
b) Above code will generate an error as multiple values after the : is not allowed in
C#.
d) one, two, three must be interfaces.

If Parent is a base class and Child is its derived class then which of the following
statements is not valid?
a) Parent p1= new Child();
c) Parent p1= new Parent();
b) Child c1= new Child();
d) Child c1= new Parent();

Any class that contain one or more abstract methods must be declared as ________.
a) interface
c) static

13
b) abstract
d) private

Which of the following are correct statements for implementing an abstract class?
a) public abstract void class ClassA
c) abstract public ClassA
b) public abstract class ClassA
d) none of above

Abstract methods holds only _______.


a) return type
c) name of method
b) All of above
d) parameters

A/An _______ can be thought as a mould of a class.


a) abstract class
c) interface
b) delegate
d) static class

Which of the following is a valid statement to implement class B in the class A.


a) class A implements B
c) class A : B
b) class A implements class B
d) class B : A

14
Properties provide the opportunity to protect a field in a class by reading and writing
to it using accessors.
a) True
b) False

What will be the output of the following program?


using System;
public class Parent
{
public virtual void Count()
{
Console.WriteLine("100");
}
}
public class Child : Parent
{
public override void Count()
{
Console.WriteLine("1000");
}
}
class Program
{
public static void Main()
{
Parent p = new Child();
p.Count();
}
}
a) 100
b) 1000
c) Compile error
d) 100 1000

What error does the following code generates when compiled?


abstract class ClassB
{
public void getNumber();
}
class ClassA : ClassB
{ }
a) The name of base class used is invalid
c) The class ClassA must declare as abstract as the class does not implements all
the methods of abstract base class.

15
b) getNumber() method must declare a body because it is not marked abstract.
d) None of the above.

What will be the output of following code when compile/run?


using System;
public class Parent
{
public virtual void Display()
{
Console.WriteLine("100");
}
}
public class Child1 : Parent
{
public override void Display()
{
Console.WriteLine("1000");
}
}
public class Child2 : Parent
{
public override void Display()
{
Console.WriteLine("1000");
}
public static void Main()
{
Child1 c1 = new Child1();
Child2 c2 = new Child2();
Parent p = c2;
c1.Display();
p.Display();
}
}
a) The code will generate an error, as the object p is not properly instantiated.
c) The output of the code will be:
1000
1000
b) The code will generate an error, as the object c2 is not properly instantiated
d) The output of the code will be:
1000
100

16
What error does the following code generates when compiled?
abstract class ClassB
{
private abstract void getNumber();
}
class ClassA : ClassB
{ }

a) The name of base class used is invalid.


c) The class ClassA must declare as abstract as the class does not implements all
the methods of abstract base class.
b) getNumber() method must declare a body because it is marked abstract.
d) The abstract member cannot be private.

What will be the output of following code when compile/run?


using System;
public class Parent
{
public virtual void Display()
{
Console.WriteLine("100");
}
}
public class Child : Parent
{
public override void Display()
{
Console.WriteLine("1000");
}
public void Display(int i)
{
Console.WriteLine("{0}", i);
}
}
class Program
{
public static void Main()
{
Parent p = new Child();

p.Display();
p.Display(90);
}
}

a) The code will generate an error, as the object p is not properly instantiated.
c) The code will generate a compilation error, as parent class does not have a
display method with one argument.
b) The output of the code will be:
17
1000
1000
d) The output of the code will be:
1000
100

What will be the output of the code below?


using System;
class Room
{
public bool isEmpty()
{
return true;
}
}
class StaffRoom : Room
{
public new bool isEmpty()
{
return false;
}
public static void Main()
{
Room R1 = new StaffRoom(); //1
Console.WriteLine(R1.isEmpty()); //2
}
}
a) True
c) False
b) The code will not compile anc generate an error at line 1.
d) The code will not compile and generate an error at line 2.

What changes should be done in the followng code so that the code does not generate
any error at compile time?
abstract class Class
{
public abstract void getNumber();
public abstract void getHeight();
public bool isEmpty() { return (true); }
}
abstract class ClassA : Class
{
public abstract void getWidth();
}
class ClassB : ClassA

18
{ }
a) Remove the abstract modifier for the getNumber(), getHeight() methods
c) Add the abstract modifier for the isEmpty() method
b) Remove the abstract modifier for the class ClassA
d) Implement the methods getNumber(), getHeight(), getWidth() in the class
ClassB.
c) Add the abstract modifier for the class ClassB

The output of below code will be:


class Room
{
int number = 0;
public bool isEmpty()
{
return (number > 0);
}
}
class StaffRoom : Room
{
int number = 10;
public new bool isEmpty()
{
return (number > 0);
}
public static void Main()
{
Room R1 = new StaffRoom();
System.Console.WriteLine(R1.isEmpty());
StaffRoom R2 = new StaffRoom();
System.Console.WriteLine(R2.isEmpty());
}
}
a) 0, 10
b) 10, 0
c) True, False
d) False, True
e) The code will generate an error.

Consider the below code:


interface IMethods
{
void F();
void G();
}
19
abstract class C : IMethods
{
void IMethods.F()
{
FF();
}

void IMethods.G()
{
GG();
}
protected abstract void FF();
protected abstract void GG();
}
The non-abstract that derives from C will have to implement:
a) FF()
b) GG()
c) All of a and b
d) None of the above

using directives are provided to facilitate the use of namespaces.


a) True
b) False

Namespaces are imported by _________ keyword.


a) using
c) system
b) class
d) namespace

The using alias directives can be used to pull out and bring into scope one component
from a namespace.
a) True
b) False

20
The _______ namespace provides the classes and methods for manipulating arrays.
a) System.IO
c) System.Array
b) System. Arr
d) Array

The ________ namespace contains all code required to interact with the including the
console output.
a) IO
c) Class
b) System
d) Namespace

When a class is used inside its namespace, the _______ of that class is used.
a) qualified name
c) unqualified name
b) namespace name
d) None of the above

_____ keyword is used to import the classes of the namespace.


a) using
c) namespace
b) class
d) import

The syntax of a predefined Sort() method is _______.


a) Arraytosort.Sort()
c) System.Array.Sort(ArrayToSort)
21
b) Arraytosort.Array.Sort()
d) System. Array. Sort()

The syntax for declaring array is:


a) arrayname DataType[];
c) DataType arrayname[];
b) arrayname[] DataType;
d) DataType[] arrayname;

The fully qualified name of class MyClass is :


namespace Space1
{
namespace Space2
{
class MyClass { }
}
}
a) Space1.MyClass()
c) Space1.Space2.MyClass()
b) Space2.MyClass()
d) Space2.Space1.MyClass()

The fully qualified name of class Book is:


namespace College.Library
{
namespace Shelf
{
class Book { }
}
}
a) Shelf.Book()
c) College.Library.Shelf.Book()
b) College.Library.Book()
d) Library.Shelf.Book()

22
What will be the output of below code:
using System;
class Test
{
static void Main()
{
int[] Array1 = { 3, 2, 1 };
int i = Array.IndexOf(Array1, 3);
Console.WriteLine(i);
}
}
a) 3
c) 1
b) 2
d) 0

using System;
class Question
{
static void Main()
{
int[] List = { 20, 30, 10 };
Console.WriteLine(Array.IndexOf(List, 30));
}
}

What will be the output of above code?


a) 3
c) The code will generate a compile time error.
b) 2
d) 1

When the array is initialized at the same time they are created, the C# compiler
determines the size of array using ________.
a) the number of items in the initialization list.
c) Both of a and b are correct.
b) the number present in the square bracket next to the data type at the right hand
side.
d) All options are incorrect.

23
using System;
class Test
{
static void Main()
{
int[] Array1 = { 3, 2, 1 };
Display1(Array1);
Array.Sort(Array1);
Display1(Array1);
}
static void Display1(Array pArray)
{
foreach (int t in pArray)
{
Console.Write(t);
}
}
}

What will be the output of above code?


a) The code will generate an error at compile time since the Sort() function of Array
returns an integer number.
c) The output of code will be
3
2
1
1
2
3
b) The output of the code will be:
321123
d) The code will generate a runtime error.

What output does the code below generate when compiled/run?


class Employee
{
public int EmployeeId;
public static Employee getEmpId(int EmpId)
{
Employee emp = new Employee();
emp.EmployeeId = EmpId;
return (emp);

24
}
}
class Test
{
public static void Main()
{
Employee[] emps = new Employee[2];
emps[0] = Employee.getEmpId(1);
emps[1] = Employee.getEmpId(2);
foreach (Employee e in emps)
System.Console.WriteLine(e.EmployeeId);
}
}

a) The code will generate a null exception, as the employees are not initialized.
c) The code will generate a compile time error at line 12 and line 13.
b) The code will compile successfully and outputs will be:
1
2
d) The code will compile successfully and output will be:
0
1

What will be the output of the code below when compiled/run?


class Test
{
public static void Print(object[] arr)
{
foreach (object p in arr)
System.Console.WriteLine(p);
}
public static void Main()
{
string s = "Programming in C#";
char[] separator = { ' ' };
string[] words = s.Split(separator);
Print(words);
}
}

a) The code will generate an error at line 10 as conversion not allowed for one
array type to another array type.
c) The code will compile successfully and output will be
Programming
in
25
C#
b) The code will generate an error at compile time at line 9 as the function Split
used is not supported string data type.
d) The code will compile successfully and nothing to be outputed.

class Test
{
public static void Main()
{
int i = 0;
char c = 's';
object[] objArray = new object[3];
objArray[0] = new object();
objArray[0] = i; //1
objArray[0] = c; //2
}
}

The above code is compiled and run. The possible error is:
a) The code will generate a compile time error at lines 1 and 2 as the array can
have only one type of data.
c) The code will compile successfully.
b) The code will generate a compile time error at lines 1 and 2 as the implicit
conversion of int and char to a object type is not possible.
d) None of options

using System;
class Test
{
public static void Main()
{
int value = Int32.Parse("99953");
double dval = Double.Parse("1.3433E+35");
Console.WriteLine(value);
Console.WriteLine(dval);
}
}

a) The code will generate a compile time error.


c) The output of above code will be
99953
1.3433E35
b) The code will generate a compile time error.
26
d) The output of above code will be
99953
1.3433E+35

namespace Space1
{
using System;
public class A
{
public static void Main()
{
A objA = new A();
Type t1 = objA.GetType();
Console.WriteLine("The type of objA is : {0} ", t1);
}
}
}

What will be the output of above code when compiled/run?


a) The code will generate a compile time error as class reference is required for
the GetType() method.
c) The type of objA is : class.A
b) The type of objA is : Space1.A
d) The type of objA is : System.Space1.A

Which of the following are true about the finally clause of try-catch-finally statements?
a) It is only executed after a catch.
c) It is alwaysclause has executed unless its thread terminates.
b) It is only executed if a catch clause has not executed.
d) It is only executed if an exception is thrown.

// Expected catch or finally


class A
{
public static void Main()
{
try
{
System.Console.WriteLine("hello");
}
}
}

27
Select the correct statement with respect to above code.
a) The code that does not throw any exception cannot be in a try block.
c) The method Main() must always throw something if the try block is used without
a catch block
b) We cannot have a try block without a catch or/and finally block.
d) None of the above.

Which of the following statements are true with respect to try-catch block?
a) try statement determines which catch should be used to handle an exception.
c) The last catch that is capable of handling the exception is executed.
b) catch statement are examined in order in which they appear.
d) All of above.

class Question
{
public static void Main()
{
Function1();
}
static void Function1()
{
try
{
System.Console.WriteLine("In Try");
return;
}
finally
{
System.Console.WriteLine("In Finally");
}
}
}

What will be the output of above code when compile/run?


a) The code will generate a compile time error as the method Function1( ) cannot
be called without an object reference.
c) The code will compile successfully and output the following text:
In Try
In Finally

28
b) The code will compile successfully and output the following text:
In Try
d) The code will compile successfully and output the following text:
In Finally

The WriteLine() method is a part of the ______ class.


a) System
b) Console
c) System.Output
d) Console.System

C# is a ____________language.
a) purely Procedure-Oriented
b) Procedure-Oriented and Object-Oriented
c) partially Procedure-Oriented
d) purely Object-Oriented

Access modifiers for variables in C# can be the following:


a) public
b) private
c) protected
d) All of them

Console.ReadLine() returns the input as a ________.


a) string
b) stream of characters
c) character
d) integer

29
In C#, datatypes are divided into two fundamental categories: value types and
reference types.
a) True
b) False

Which of the following is a correct statement to declare the class MyClass?


a) Class myclass
b) class MyClass
c) class Myclass
d) Class MyClass

A constructor is a special type of a _______ in a class.


a) variable
b) method
c) instance
d) struct

The constructor without parameters is called _________.


a) main constructor
b) default constructor
c) zero valued constructor
d) non-parameterized constructor

Which of the following sentences are true about Constructors?


a) The constructor can have the same name as that of its class.
b) The constructor may or may not have name same as that of the name of its class.
c) The constructor can have the same name as one of the methods in the class.
d) The constructor must have the same name as that of the name of its class.

30
Methods can be overloaded in C# by:
a) specifying different names for the methods.
b) specifying different types of parameters.
c) a and b are true.
d) a and b are false.

Which of the following statements is correct for a method, which is overriding the
following method:
public void add(int a) {…}
a) the overriding method must return void
c) the overriding method can return whatever it likes
b) the overriding method must return int
d) None of the above

The ______ method is used to assign some value to a data member in a class.
a) value
b) get
c) set
d) find

Does C# support multiple inheritance?


1. Yes
2. Partially
3. No
4. None of the above

How do you inherit from a class on C#?


1. Place a semicolon (;) and then the name of the base class.
2. Place a dot (.) and then the name of the base class.

31
3. Place a scope resolution and then the name of the base class
4. Place a colon (:) and then the name of the base class

If a method is marked as protected who can access it?


1. Classes that are both in the same assembly and derived from the declaring class.
2. Only methods that are in the same class as the method in question.
3. Internal methods can be only be called using reflection.
4. Classes within the same assembly, and classes derived from the declaring class.

How do you retrieve the value of the Name property?


Scenario: A public string property called Name has been added to class called
Employee. Person is an object of Employee class.
1. Person.Name
2. Employee!Person.Name
3. Person ->Name
4. Employee.Name

C# supports inheritance?
1. Yes
2. No
3. Sometime
4. Don’t know

Which of the following is a valid statement (I is an integer and S is a string)?


1. I = int.Parse(S)
2. I = Parse(S)
3. S = Parse(I)
4. None

32
We can make a property WriteOnly by:
1. Removing Set accessor
2. Removing Get accessor

We can make a property ReadOnly by:


1. Removing Set accessor
2. Removing Get accessor

In C# single line comments are implemented by:


1. !--Data
2. //Data
3. /*Data
4. –Data

In C# multiline comments are implemented by:


1. !--Data
2. //Data
3. /*Data*/
4. <--Data-->

The basic Object – Oriented concepts are:


1. Abstraction, Encapsulation, OverLoading, Overriding
2. Abstraction, Encapsulation, Overriding, Inheritance
3. Abstraction, Encapsulation, Polymorphism, Inheritance
4. Abstraction, Encapsulation, OverLoading, Inheritance

In C#, default access modifier for fields in class is:


1. public
2. private

33
3. internal
4. protected

It is possible for a derived class to define a member that has the same name as the
member in its base class. Which of the following keywords would you use if your intent
is to hide the base class member?
1. virtual
2. sealed
3. ref
4. new

A new object that is created based on a class is referred to as a(n) _________ of the
class.
A) instance
B) property
C) method
D) copy

A named memory location that holds data that can be changed during project
execution is called a(n) _________.
A) identifier
B) variable
C) named constant
D) constant

The acronym OOP stands for _______.


A) Object-Ordering Programs
B) Other-Object Procedures
C) Object-Organized Projects
D) Object-Oriented Programming
34
_______ refers to the combination of characteristics of an object along with its
behaviors.
A) Reusability
B) Inheritance
C) Encapsulation
D) Polymorphism

_______ refers to data hiding.


A) Encapsulation
B) Instantiation
C) Inheritance
D) Polymorphism

A big advantage of OOP over traditional programming is _______.


A) the objects are all declared public
B) the ability to reuse classes
C) the convenience of giving all objects in a project the same name
D) every object shares the same properties

A constructor must be _________ for the object created to execute the method.
A) functions
B) strings
C) public
D) private

Get and Set accessor methods must be _______ in order to allow other modules (forms
or classes) to assign and retrieve their values.
A) functions
B) strings
35
C) public
D) private

The Get accessor method _______.


A) retrieves the current value of a property
B) allows you to get items from a listbox
C) allows a class to set its properties
D) returns the hidden enumerator

Objects have properties and methods.


A) True
B) False

The acronym OOP stands for Object-Oriented Procedures.


A) True
B) False

Properties are actions that can be performed by a class of objects.


A) True
B) False

When you have finished defining a class, you may then create as many instances of the
class as you need using the new keyword.
A) True
B) False

Inheritance is the ability to create a new class from an existing class.


A) True
B) False

36
Which of the following keyword is used for including the namespaces in the program
in C#?
A - imports
B - using
C - exports
D - None of the above.

Which of the following statements is correct about encapsulation?


A - Encapsulation is defined as the process of enclosing one or more items within a
physical or logical package.
B - Encapsulation, in object oriented programming methodology, prevents access to
implementation details.
C - Abstraction allows making relevant information visible and encapsulation enables
a programmer to implement the desired level of abstraction.
D - All of the above.

Which of the following is the correct about class member variables?


A - Member variables are the attributes of an object (from design perspective) and they
are kept private to implement encapsulation.
B - These private variables can only be accessed using the public member functions.
C - Both of A and B.
D - None of the above.

The assignment operators cannot be overloaded.


A - True
B - False

Which of the following access specifier in C# allows a class to expose its member
variables and member functions to other functions and objects?
A - public

37
B - private
C - protected
D - internal

Which of the following access specifier in C# allows a class to hide its member variables
and member functions from other functions and objects?
A - public
B - private
C - protected
D - internal

The comparison operators can be overloaded.


A - True
B - False

Which of the following statements is correct about access specifiers in C#?


A - Encapsulation is implemented by using access specifiers.
B - An access specifier defines the scope and visibility of a class member.
C - Both of the above.
D - None of the above.

Which of the following is true about try block in C#?


A - A try block identifies a block of code for which particular exceptions is activated.
B - It is followed by one or more catch blocks.
C - Both of the above.
D - None of the above.

38
Which of the following is true about catch block in C#?
A - A program catches an exception with an exception handler at the place in a program
where you want to handle the problem.
B - The catch keyword indicates the catching of an exception.
C - Both of the above.
D - None of the above.

The operator used to access member function of a class?


a) :
b) ::
c) .
d) #

Correct way of declaration of object of the class Name is:


a) Name n = new Name();
b) n = Name();
c) Name n = Name();
d) n = new Name();

In C#, the data members of a class by default are _______.


a) protected, public
b) private, public
c) private
d) public

What does the following code signify?


class a
{
………….

39
}
class b : a
{
………….
}
a) Declaration of a base class
b) Declaration of a sub class
c) Declaration of base class & sub class and how subclass inherits the base class
d) None of the mentioned

In inheritance concept, which of the following members of base class are accessible to
derived class members?
a) static
b) protected
c) private
d) shared

Which form of inheritance is not supported directly by C# .NET?


a) Multiple inheritance
b) Multilevel inheritance
c) Single inheritance
d) Hierarchical inheritance

If no access modifier for a class is specified, then class accessibility is defined as?
a) public
b) protected
c) private
d) internal

40
Which of these keywords is used to refer to member of base class from a sub class?
a) upper
b) base
c) this
d) None of the mentioned

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


a) :
b) &
c) ::
d) extends

What is the output of the following set of code?


using System;
public class BaseClass
{
public BaseClass()
{
Console.WriteLine("I am a base class");
}
}
public class ChildClass : BaseClass
{
public ChildClass()
{
Console.WriteLine("I am a child class");
}
static void Main()
{
ChildClass CC = new ChildClass();
Console.ReadKey();
}
}
a) I am a base class
I am a child class
b) I am a child class
I am a base class
c) compile time error
d) None of the mentioned

41
The process of defining two or more methods within the same class that have same
name but different parameters list?
a) method overloading
b) method overriding
c) Encapsulation
d) None of the mentioned

Which of these can be overloaded?


a) Constructors
b) Methods
c) Both a & b
d) None of the mentioned

What could be the output for the set of code?


using System;
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();
}
}
a) 8

42
8
b) 0
2
c) 8
10
d) 7
8

Which keyword is used to refer baseclass constructor to subclass constructor?


a) This
b) static
c) base
d) extend

Select the correct statement about an Exception?


a) It occurs during loading of program
b) It occurs during Just-In-Time compilation
c) It occurs at run time
d) All of the above mentioned

Choose the correct output for the given set of code:


using System;
class program
{
static void Main(string[] args)
{
int i = 5;
int v = 40;
int[] p = new int[4];
try
{
p[i] = v;
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine("Index out of bounds");
}
Console.WriteLine("Remaining program");

43
}
}

a) value 40 will be assigned to a[5];


b)
Index out of bounds
Remaining program
c) Remaining program
d) None of the above mentioned

Choose the correct output for the given set of code:


using System;
class program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("CSharp" + " " + 1 / Convert.ToInt32(0));
}
catch (ArithmeticException e)
{
Console.WriteLine("Java");
}
Console.ReadLine();
}
}

a) CSharp
b) Java
c) Run time error
d) CSharp 0

What would be the output of following code snippet?


using System;
class program
{
static void Main(string[] args)
{
try
{
int a, b;
b = 0;
a = 10 / b;
Console.WriteLine("A");
}
44
catch (ArithmeticException e)
{
Console.WriteLine("B");
}
Console.ReadLine();
}
}

a) A
b) B
c) Compile time error
d) Run time error

An object is composed of:


A. Properties
B. Methods
C. Events
D. All of the above

Which statement about objects is true?


A. One object is used to create one class.
B. One class is used to create one object.
C. One object can create many classes.
D. One class can create many objects.

Data can be protected using _____________ such as public, private and protected.
A. default constructors
B. method overloading
C. access specifiers
D. member functions

Identify the error with the constructor shown in the following fragment?
class Invent
{
int x, y, z;

45
public int Invent()
{
}
}

A. Data types must have private access specifier.


B. A constructor cannot have a return value.
C. A constructor must have parameter in parenthesis.
D. A class must have semicolon (;) at the end of the class.

A class named Car inherits publicly all properties of another class named Vehicle.
Which of following code describes the situation?
A. class Car : public Vehicle { }
B. class Vehicle : public Car { }
C. class Car : Vehicle { }
D. class Car : protected Vehicle { }

To make a member accessible within a hierachy, but private otherwise, what access
specifier do you use?
A. Public
B. Private
C. Protected
D. Vitural

A constructor ______________.
A. must have the same name as the class it is declared within.
B. is used to create objects.
C. maybe declared private.
D. All of the above.

46
Which of the following statement shows correct syntax to create an object of the Piggy
class?
A. Piggy new tom = Piggy();
B. Piggy tom = new Piggy();
C. Piggy = new tom();
D. Tom = new Piggy;

An object is _____________.
A. one instantce of a class.
B. another word for a class.
C. a class with static methods.
D. a method that accesses class attributes.

A derived class has access to the data attributes of a base class _____________
A. if the base class data is declared protected.
B. if the base class data is declared private or protected.
C. in all cases due to inheritance.
D. only if the primary program class is declared public.

A class ________________
A. is a user-defined data type.
B. combines both data and the methods that act upon the data in the same
module.
C. is one instance of a more general data type.
D. is both A and B.

An object _______________
A. is a user-defined data type.
B. combines both data and the methods that act upon the data.
C. is one instance of a more general data type.
D. is both A and B.

47
The data in a class are also called ____________
A. attributes.
B. instance variables.
C. fields.
D. All of the above.

Methods are ________________


A. action modules that process data.
B. class variables that store information.
C. instances of a class.
D. None of the above.

Object-Oriented Programming is characterized by using


A. Encapsulation.
B. Inheritance.
C. Polymorphism.
D. All of the above.

A constructor is ____________
A. A method with the same indentifier as the class identifier.
B. Neither a void method nor a return method.
C. Called during the instantiation of a new object.
D. All of the above.

Data can be protected using _________ such as public, private and protected.
A. Default constructor
B. Method overloading
C. Access specifiers
D. Member functions

48
___________ is a programming paradigm that uses object data structures consisting
of data and methods and their interaction with design applications computer
programs.
A. Structured programming
B. Inheritance
C. Object-Oriented programming
D. Encapsulation

Number of constructors a class can define is?


a) 1
b) 2
c) Any number
d) None of the mentioned

Correct way to define object of sample class in which code will work correctly is:
class abc
{
int i;
float k;
public abc(int ii, float kk)
{
i = ii;
k = kk;
}
}

a) abc s1 = new abc(1);


b) abc s1 = new abc();
c) abc s2 = new abc(1.4f);
d) abc s2 = new abc(1, 1.4f);

Constructors are used to ________.


a) initialize the objects
b) construct the data members
c) Both a & b.
d) None of the mentioned.
49
Can the method add() be overloaded in the following ways in C#?
public int add() { }
public float add() { }
a) True
b) False

What is the return type of constructors?


a) int
b) float
c) void
d) None of the mentioned

Which method has the same name as that of its class?


a) Delete
b) Class
c) Constructor
d) None of mentioned

Polymorphism occurs when the methods of the child class ________


A. override the parent class methods but maintain the implementation.
B. maintain the same return type and arguments as the parent class, but
implement it differently.
C. have different return types and arguments than the parent class.
D. are virtual.

A ___________ creates an object by copying variables from another object.


A. copy constructor
B. default constructor
C. invoking constructor
D. calling constructor

50
The methods that have the same name, but different parameter lists and different
definitions is called ___________.
A. Method Overloading
B. Method Overriding
C. Method Overwriting
D. Method Overreading

C# does not support ______________.


A. Abstraction
B. Polymorphism
C. Multiple inheritance
D. Inheritance

Two methods with the same name but with different parameters.
A. Overloading
B. Multiplexing
C. Duplexing
D. Loading

Different ways a method can be overloaded in C#:


A. Different parameter data types.
B. Different order of parameters.
C. Different number of parameters.
D. All of the above.

Find any errors in the following BankAccount constructor:


public int BankAccount()
{
Balance = 0;
}
A. Name
B. Formal parameters
C. Return type

51
D. No errors

A destructor is a method that executes automatically when a(n) ___________ is


destroyed.
A) variable
B) argument
C) class
D) object

Which of the following is part of an object?


a.) Methods
b.) Properties
c.) Instances
d.) Both a and b.

Which is true about objects?


a.) Objects are used to create classes.
b.) Objects are analogous to blueprints.
c.) Objects combine actions and data.
d.) Both a and b.

Properties are used to represent:


a.) actions
b.) classes
c.) data
d.) instances

52
Methods are used to represent:
a.) actions
b.) classes
c.) data
d.) instances

Which feature is needed to make a programming language object oriented?


a.) Encapsulation
b.) Inheritance
c.) Polymorphism
d.) All of the above.

Encapsulation makes it easier to:


a.) reuse and modify existing modules of code.
b.) write and read code by sharing method names.
c.) hide and protect data from external code.
d.) Both a and b.

Inheritance makes it easier to:


a.) reuse and modify existing modules of code.
b.) write and read code by sharing method names.
c.) hide and protect data from external code.
d.) Both a and b.

Polymorphism makes it easier to:


a.) reuse and modify existing modules of code.
b.) write and read code by sharing method names.
c.) hide and protect data from external code.
d.) Both a and b.

53
When using encapsulation how should data be shared with external code?
a.) Public variables
b.) Methods
c.) Properties
d.) Private variables

Which statement is true?


a.) A base class inherits some of the properties of a derived class.
b.) A base class inherits all of the properties of a derived class.
c.) A derived class inherits some of the properties of a base class.
d.) A derived class inherits all of the properties of a base class.

Polymorphism can apply to:


a.) math operators.
b.) method names.
c.) object names.
d.) Both a and b.

With polymorphism:
a.) one method can have multiple names.
b.) one object can have multiple names.
c.) many methods can share the same name.
d.) many objects can share the same name.

Which element of a class is optional?


a.) Constructors
b.) Fields
c.) Methods
d.) Properties

54
e.) All of the above.

What is the suggested order for the definition of class elements from first to last?
a.) Constructs, fields, methods, properties
b.) Properties, constructs, fields, methods
c.) Fields, properties, constructs, methods
d.) Constructs, properties, fields, methods

The standard for designing a field is that it be defined as a:


a.) private method.
b.) public method.
c.) private variable.
d.) public variable.

A constructor is a special type of _____


a.) class.
b.) field.
c.) method.
d.) property.

Which is true for constructors in a class?


a.) All constructors must have the same number of parameters.
b.) All constructors must be the same parameter data type.
c.) No two constructors in a class can have the same list of parameters.
d.) Only two constructors in a class can have the same list of parameters.

Objects cannot be created for _________ class.


[A] static
[B] student

55
[C] abstract
[D] struct

Static class can have _________ members.


[A] static
[B] abstract
[C] static and non static.
[D] void

_________ is method modifier that indicates a method can be overridden by a derived


class.
[A] Value
[B] Get
[C] Set
[D] Virtual

_________ members are accessible by any method of any class.


[A] Protected
[B] Private
[C] Public
[D] Internal

_________ members are accessible only by the methods of its class.


[A] Protected
[B] Private
[C] Public
[D] Internal

56
The class which derives the properties of another class is called _________ class.
[A] derived
[B] base
[C] derivation
[D] basic

A super class is also called as _________.


[A] base class
[B] derived class
[C] sub class
[D] inherit class

Which of the following keyword is used to change the data and behavior of a base class
by replacing a member of a base class with a new derived member?
[A] new
[B] base
[C] overloads
[D] override

The _________ block is guaranteed to be executed regardless of whether an


exception is thrown.
[A] finally
[B] throws
[C] try
[D] catch

The data members of a class by default are?


A. protected, public
B. private, public

57
C. private
D. public

What will be the output of the following code snippet?


using System;
class sample
{
int i;
double k;
public sample(int ii, double kk)
{
i = ii;
k = kk;
double j = (i) + (k);
Console.WriteLine(j);
}
~sample()
{
double j = i - k;
Console.WriteLine(j);
}
}
class Program
{
static void Main(string[] args)
{
sample s = new sample(9, 2.5);
}
}
A. 0 0
B. 11.5 0
C. Compile-time error
D. 11.5 6.5

What will be the output of the following code snippet?


using System;
class sample
{
public sample()
{
Console.WriteLine("constructor 1 called");
}
public sample(int x)
{
int p = 2;
int u;
u = p + x;
Console.WriteLine("constructor 2 called");
}
}

58
class Program
{
static void Main(string[] args)
{
sample s = new sample(4);
sample t = new sample();
Console.ReadLine();
}
}
A.
constructor 1 called
constructor 2 called
B.
constructor 2 called
constructor 1 called
C.
constructor 2 called
constructor 2 called
D. error

Which of the following keywords is used to refer base class constructor to subclass
constructor?
A. this
B. static
C. base
D. extend

What is output of the code?


static void Main(string[] args)
{
Mul();
m();
Console.ReadLine();
}
static void Mul()
{
Console.WriteLine("4");
}
static void m()
{
Console.WriteLine("3");
59
Mul();
}
a. 4 3 3
b. 4 4 3
c. 4 3 4
d. 3 4 4

When a function fun() is to receive an int, a single and a double and it is to return a
decimal, then the correct way of defining this function is?
a.
static fun(int i, single j, double k)
{
return decimal;
}
b.
static decimal fun(int i, single, double k)
{
}
c.
decimal fun(int i, single j, double k)
{
}
d.
decimal static fun(int i, single j, double k)
{
}

What is the output for the following set of code:


static void Main(string[] args)
{
int i = 10;
double d = 35.78;
fun(i);
fun(d);
Console.ReadLine();
}
static void fun(double d)
{
Console.WriteLine(d);
}
a.
35.78
10
60
b.
10
35.00
c.
10
35.78
d. None of the mentioned

Which of the following statements is correct about constructors?


a. If we provide a one-argument constructor then the compiler still provides a default
constructor.
b. Static constructors can use optional arguments.
c. Overloaded constructors cannot use optional arguments.
d. If we do not provide a constructor, then the compiler provides a default constructor.

Which of the following is the correct way to define the constructor(s) of the Sample
class if we are to create objects as per the C# code snippet given below?
Sample s1 = new Sample();
Sample s2 = new Sample(9, 5.6f);
a.
public Sample()
{
i = 0;
j = 0.0f;
}
public Sample(int ii, float jj)
{
i = ii;
j = jj;
}
b.
public Sample(Optional int ii = 0, Optional float jj = 0.0f)
{
i = ii;
j = jj;
}
c.

61
public Sample(int ii, float jj)
{
i = ii;
j = jj;
}
d.
Sample s;

In which of the following should the methods of a class differ if they are to be treated
as overloaded methods?
1. Type of arguments
2. Return type of methods
3. Number of arguments
4. Names of methods
5. Order of arguments
a. 2, 4
b. 3, 5
c. 1, 3, 5
d. 3, 4, 5

How many times can a constructor be called during lifetime of the object?
a. As many times as we call it.
b. Only once.
c. Depends upon a Project Setting made in Visual Studio.NET.
d. Any number of times before the object gets garbage collected.

Which of the following statements is correct about the C# code snippet given below?
class Sample
{
private int i;
public float j;
private void DisplayData()
{
Console.WriteLine(i + " " + j);
}
public void ShowData()
{
Console.WriteLine(i + " " + j);

62
}
}
a. j cannot be declared as public.
b. DisplayData() cannot be declared as private.
c. DisplayData() cannot access j.
d. There is no error in this class.

Which of the following is the correct way to create an object of the class Sample?
1. Sample s = new Sample();
2. Sample s;
3. Sample s; s = new Sample();
4. s = new Sample();
a. 1, 3
b. 2, 4
c. 1, 2, 3
d. 1, 4

Which of the following will be the correct output for the C# program given below?
namespace CompSciBitsConsoleApplication
{
class Sample
{
int i;
float j;
public void SetData(int i, float j)
{
i = i;
j = j;
}
public void Display()
{
Console.WriteLine(i + " " + j);
}
}
class MyProgram
{
static void Main(string[] args)
{
Sample s1 = new Sample();
s1.SetData(10, 5.4f);
s1.Display();
}
}
}
63
a. 0 0
b. 10 5.4
c. 10 5.400000
d. 10 5

Which of the following statements are correct?


1. Data members ofa class are by default public.
2. Data members of a class are by default private.
3. Member functions of a class are by default public.
4. A private function of a class can access a public function within the same
class.
5. Member function of a class are by default private.
a. 1, 3, 5
b. 1, 4
c. 2, 4, 5
d. 1, 2, 3

Which of the following statements is correct about the C# code snippet given below?
namespace CompSciBitsConsoleApplication
{
class Sample
{
public int index;
public int[] arr = new int[10];

public void fun(int i, int val)


{
arr[i] = val;
}
}
class MyProgram
{
static void Main(string[] args)
{
Sample s = new Sample();
s.index = 20;
Sample.fun(1, 5);
s.fun(1, 5);
}
}
}

64
a. s.index = 20 will report an error since index is public.
b. The call s.fun(1, 5) will work correctly.
c. Sample.fun(1, 5) will set a value 5 in arr[ 1 ].
d. The call Sample.fun(1, 5) cannot work since fun() is not a shared function.

Which of the following statements are correct about the C# code snippet given below?
sample c;
c = new sample();
1. It will create an object called sample.
2. It will create a nameless object of the type sample.
3. It will create an object of the type sample on the stack.
4. It will create a reference c on the stack and an object of the type sample on
the heap.
5. It will create an object of the type sample either on the heap or on the stack
depending on the size of the object.
a. 1, 3
b. 2, 4
c. 3, 5
d. 4, 5

The operator used to access member function of a class?


a.:
b.::
c. .
d. #

Select the output for the following set of code:


class sample
{
public int i;
public int j;
public void fun(int i, int j)

65
{
this.i = i;
this.j = j;
}
}
class Program
{
static void Main(string[] args)
{
sample s = new sample();
s.i = 1;
s.j = 2;
s.fun(s.i, s.j);
Console.WriteLine(s.i + " " + s.j);
Console.ReadLine();
}
}
a. Error while calling s.fun() due to inaccessible level
b. Error as ‘this’ reference would not be able to call ‘i’ and ‘j’
c. 1 2
d. Runs successfully but prints nothing

Correct way of declaration of object of the class ABC is?


a. ABC n = new ABC();
b. n = ABC ();
c. ABC n = ABC();
d. n = new ABC();

The data members of a class by default are _________.


a. protected, public
b. private, public
c. private
d. public

Select the output for the following set of code:


class z
{
public string name1;
public string address;
public void show()
{

66
Console.WriteLine("{0} is in city {1}", name1, " ", address);
}
}
class Program
{
static void Main(string[] args)
{
z n = new z();
n.name1 = "harsh";
n.address = "new delhi";
n.show();
Console.ReadLine();
}
}
a. Syntax error
b. {0} is in city {1} harsh new delhi
c. harsh is in new delhi
d. Run successfully prints nothing

The output of code is?


class test
{
public void print()
{
Console.WriteLine("Csharp");
}
}
class Program
{
static void Main(string[] args)
{
test t;
t.print();
Console.ReadLine();
}
}
a. Code runs successfully prints nothing
b. Code runs and prints “Csharp”
c. Syntax error: Use of unassigned local variable 't'
d. None of the mentioned

Correct way to define object of sample class in which code will work correctly is:
class abc
{
int i;
float k;
public abc(int ii, float kk)
{

67
i = ii;
k = kk;
}
}
a. abc s1 = new abc(1);
b. abc s1 = new abc();
c. abc s2 = new abc(1.4f);
d. abc s2 = new abc(1, 1.4f);

Correct statement about constructors in C# is:


a. Constructors can be overloaded.
b. Constructors are never called explicitly.
c. Constructors have same name as name of the class.
d. All of the mentioned

Constructors are used to __________.


a. initialize the objects
b. construct the data members
c. initialize the objects & construct the data members
d. None of the mentioned

What is output of the following section of code?


class abc
{
public static void a()
{
console.writeline("first method");
}
public void b()
{
a();
console.writeline("second method");
}
public void b(int i)
{
console.writeline(i);
b();
}
}
class program
{

68
static void main()
{
abc k = new abc();
abc.a();
k.b(20);
}
}
a.
second method
20
second method
first method
b.
first method
20
first method
second method
c.
first method
20
d.
second method
20
first method

What is the return type of constructors?


a. int
b. float
c. void
d. none of the mentioned

69
Which of these base class are accessible to the derived class members?
a. static
b. protected
c. private
d. shared

What will be the output of the given code snippet?


class access
{
public int x;
private int y;
public void cal(int a, int b)
{
x = a + 1;
y = b;
}
}
class Program
{
static void Main(string[] args)
{
access obj = new access();
obj.cal(2, 3);
Console.WriteLine(obj.x + " " + obj.y);
}
}
a. 3 3
b. 2 3
c. Run time error
d. Compile time error

What will be the output of the given code snippet?


class access
{
public int x;
private int y;
public void cal(int a, int b)
{
x = a + 1;
y = b;
}
public void print()
{
Console.WriteLine(" " + y);
}
}
class Program

70
{
static void Main(string[] args)
{
access obj = new access();
obj.cal(2, 3);
Console.WriteLine(obj.x);
obj.print();
Console.ReadLine();
}
}
a. 2 3
b. 3 3
c. Run time error
d. Compile time error

What will be the output of the following set of code?


class sum
{
public int x;
public int y;
public int add(int a, int b)
{
x = a + b;
y = x + b;
return 0;
}
}
class Program
{
static void Main(string[] args)
{
sum obj1 = new sum();
sum obj2 = new sum();
int a = 2;
obj1.add(a, a + 1);
obj2.add(5, a);
Console.WriteLine(obj1.x + " " + obj2.y);
Console.ReadLine();
}
}
a. 6, 9
b. 5, 9
c. 9, 10
d. 3, 2

71
What will be the output of the following set of code?
class static_out
{
public static int x;
public static int y;
public int add(int a, int b)
{
x = a + b;
y = x + b;
return 0;
}
}
class Program
{
static void Main(string[] args)
{
static_out obj1 = new static_out();
static_out obj2 = new static_out();
int a = 2;
obj1.add(a, a + 1);
obj2.add(5, a);
Console.WriteLine(static_out.x + " " + static_out.y);
Console.ReadLine();
}
}
a. 7 7
b. 6 6
c. 7 9
d. 9 7

Which of the following statements are incorrect?


a. public members of class can be accessed by any code in the program
b. private members of class can only be accessed by other members of the class
c. private members of class can be inherited by a sub class, and become protected
members in sub class
d. protected members of a class can be inherited by a sub class, and become private
members of the sub class

What will be the output of code snippet?


class test
{
public int a;
public int b;
public test(int i, int j)
{

72
a = i;
b = j;
}
public void meth(test o)
{
o.a *= 2;
o.b /= 2;
}
}
class Program
{
static void Main(string[] args)
{
test obj = new test(10, 20);
obj.meth(obj);
Console.WriteLine(obj.a + " " + obj.b);
Console.ReadLine();
}
}
a. 20, 40
b. 40, 20
c. 20, 10
d. 10, 20

Accessibility modifiers defined in a class are?


a. public, private, protected
b. public, internal, protected internal.
c. public, private, internal, protected internal.
d. public, private, protected, internal, protected internal

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;

73
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();
}
}

a) 1
b) 3
c) 2
d) Compile time error

Which statement should be added in function a() of class y to get output “I love
Csharp”?
using System;
class x
{
public void a()
{
Console.Write("I love Csharp");
}
}
class y : x
{
public void a()
{
/* add statement here */

74
base.a();
}
}
class Program
{
static void Main(string[] args)
{
y obj = new y();
obj.a();
}
}

a) x.a();
b) a();
c) base.a();
d) x:a();

Select the output for the following set of code?


using System;
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();
}
}

a) 2 1
b) 1 0

75
c) 0 2
d) 1 2

Select the output of the following set of code?


using System;
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();
}
}

a) 1, 3
b) 2, 3
c) 1, 2
d) compile time error

_________ is not an access modifier.


[A] public
[B] private
[C] protect
[D] internal

"new" is used for _________ the objects.


[A] creating
76
[B] modifying
[C] allocating memory for
[D] deallocating memory of

Which is not a keyword in C#.


[A] this
[B] finally
[C] throw
[D] external

_________ is an access modifier.


[A] internal
[B] external
[C] extrim
[D] interim

Operators or functions to have more than one form is _________.


[A] Inheritance
[B] Overloading
[C] Polymorphism
[D] Abstraction

Wrapping up of data with its properties is called _________.


[A] Inheritance
[B] Polymorphism
[C] Abstraction.
[D] Encapsulation

77
What is the output for the following set of code :
using System;
class Output
{
static void Main(string[] args)
{
int i = 10;
double d = 35.78;
fun(i);
fun(d);
Console.ReadLine();
}
static void fun(double d)
{
Console.Write($"{d} ");
}
}
A. 35.78 10
B. 10 35.00
C. 10 35.78
D. None of the mentioned

How many public members are allowed in a class?


a) Only 1
b) At most 7
c) Exactly 3
d) As many as required

The ______ method is used to assign some value to a data member in a class.
a) value c) get
b) set d) find

What will be printed to standard output?


using System;
class Super
{
public int index = 5;
public virtual void printVal()
{
System.Console.WriteLine("Super");
}
}
class Sub : Super
{
int index = 2;
public override void printVal()
{

78
System.Console.WriteLine("Sub");
}
}
public class Runner
{
public static void Main()
{
Super sup = new Sub();
System.Console.Write(sup.index + ", ");
sup.printVal();
}
}
a) The code will not compile.
b) The code compiles and "5, Super" is printed on the standard output.
c) The code compiles and "5, Sub" is printed on the standard output.
d) The code compiles and "2, Super" is printed on the standard output.

What will happen if you compile/run the following code?


public class Q21
{
int maxElements;
public void Q21()
{
maxElements = 100;
System.Console.Write(maxElements);
}
public Q21(int i)
{
maxElements = i;
System.Console.Write(maxElements);
}
public static void Main()
{
Q21 a = new Q21();
Q21 b = new Q21(999);
}
}

a) Prints 100 and 999.


b) Prints 999 and 100.
c) Compilation error, variable maxElements was not initialized.
d) Compilation error, consstructor has no return type.

At least one _______ constructor must be declared to suppress the automatic


generation of a default constructor.
a) default
c) private
b) static

79
d) parameterized

The method that overrides a method in the base class must be prefixed with the ____
keyword.
a) virtual
c) sealed
b) new
d) overridden

The object invokes the default constructor when no parameters were passed to it.
a) True
b) False

The constructor without parameters is called _________.


a) main constructor
c) default constructor
b) zero valued constructor
d) non-parameterized constructor

A constructor is a special type of a _______ in a class.


a) variable
c) method
b) instance
d) struct

Two methods with the same name but with different parameters.
Overloading
Loading
Multiplexing
Duplexing

One of the OOP's concept in .NET?


encapsulation

80
public
private
protected

What OOP methodology is shown below:


public class Department
{
private string departname;
// Accessor
public string GetDepartname()
{
return departname;
}
// Mutator
public void SetDepartname(string a)
{
departname = a;
}
}

Polymorphism
Encapsulation
Inheritance
Abstraction

Choose the best answer below of what the code best describes:
using System;
public class DrawingObject
{
public virtual void Draw()
{
Console.WriteLine("I'm just a generic drawing object.");
}
}
public class Line : DrawingObject
{
public override void Draw()
{
Console.WriteLine("I'm a Line.");
}
}
public class Circle : DrawingObject
{
public override void Draw()
{
Console.WriteLine("I'm a Circle.");
}
}
public class DrawDemo
{
public static void Main()
{

81
DrawingObject draw = new Circle();
draw.Draw();
Console.ReadKey();
}
}

Inheritance
Encapsulation
Polymorphism
Abstraction

To override the method in C#, it has to be declared as virtual in the base class.
True
False

Which of the following is not a access specifier in C#?


private
public
inherited
internal

What is the outcome of the following:


using System;
sealed class MyClass
{
public int x;
public int y;
}
class MainClass
{
public static void Main()
{
MyClass mC = new MyClass();
mC.x = 110;
mC.y = 150;
Console.WriteLine("x = {0}, y = {1}", mC.x, mC.y);
}
}
Compile error - Cannot instantiate a sealed class
x = 110, y = 150
Runtime error - Cannot instantiate a sealed class
None of the above

82
What is the output of the following:
using System;
public class A
{
public int num { get; set; }
}
class Program
{
static void Main(string[] args)
{
A a = new A();
a.num = 12;
ChangeString(a);
Console.WriteLine(a.num);
}
public static void ChangeString(A obj)
{
obj.num = 99;
}
}
runtime error
12
99
compile error

Select correct console output?


using System;
class A
{
public A()
{
Console.WriteLine("A Class");
}
}
class B : A
{
public B()
{
Console.WriteLine("B Class");
}
}
class Program
{
static void Main(string[] args)
{
B b = new B();
Console.ReadLine();
}
}

a.
A Class
B Class

83
b.
B Class
A Class
c.
Error

Properties provide the opportunity to protect a field in a class by reading and writing
to it using accessors.
a) True
b) False

_____ keyword is used to import the classes of the namespace.


a) using
c) namespace
b) class
d) import

Actions associated with objects are called _______________.


A) fields
B) constructors
C) properties
D) methods

Which of the following data types does not store whole numbers (numbers with no
decimal places)?
A) int
B) long
C) short
D) float

84
C# does not support multiple inheritance.
A - True
B - False

When we call a constructor method among different given constructors. We match the
suitable constructor by matching the name of constructor first, then the number and
then the type of parameters to decide which constructor is to be overloaded. The
process is also known as?
a) Method overriding
b) Inheritance
c) Polymorphism
d) Encapsulation

Which of these keywords is not a part of exception handling?


a) try
b) finally
c) thrown
d) catch

Which of these keywords must be used to monitor exceptions?


a) try
b) finally
c) throw
d) catch

In the procedure-oriented approach, all data are shared by all functions. (False)

One of the major characteristic of OOP is the division of programs into objects that
represent real-world entities. (True)

85
Object-Oriented programming languages permit reusability of the existing code. (True)

Protecting data from access by unauthorized functions is called data hiding. (True)

Wrapping up of data of different types and functions into a unit is known as


encapsulation. (True)

A class permits us to build user-defined data types. (True)

Which language is not a true OOP language?


A. Visual Basic 6
B. C#
C. C++
D. Java

What are the two important elements of the object-oriented approach?


A. Class and Object
B. Class and Function
C. Inheritance and Polymorphism
D. Inheritance and Abstraction

_________ is an accessor that sets the value of a property


[A] Assign
[B] Set
[C] Get
[D] Is

Which among the following is NOT an exception?


[A] Stackoverflow
[B] Arithmeticoverflow

86
[C] ArrayOutofBounds
[D] IncorrectArithmeticOverflow

A number divided by zero is _________ Exception.


[A] ArgumentNull
[B] Invalidcast
[C] OverFlow
[D] Arithmetic

Any real word entity is called _________.


[A] object
[B] attribute
[C] characteristic
[D] class

Which of the following should be used to implement a 'Like a' or a 'Kind of relationship
between two entities?
[A] Polymorphism
[B] Containership
[C] Templates
[D] Inheritance

Choose the wrong statement about properties used in C#.Net?


A. Each property consists of accessor as getting and setting.
B. A property cannot be either read or write-only.
C. Properties can be used to store and retrieve values to and from the data
members of a class.
D. Properties are like actual methods that work like data members.

87
Abstract class contains _____.
A. Abstract methods
B. Non abstract methods
C. Both
D. None

The default scope for the members of an interface is _____.


A. private
B. public
C. protected
D. internal

What will be the output of the C# code snippet given below?


namespace CompSciBitsConsoleApplication
{
class Sample
{
static Sample()
{
Console.Write("Sample class ");
}
public static void Bits1()
{
Console.Write("Bits1 method ");
}
}
class MyProgram
{
static void Main(string[] args)
{
Sample.Bits1();
}
}
}
a. Sample class Bits1 method
b. Bits1 method
c. Sample class
d. Bits1 method Sample class

88
Select output for the following set of code.
class sample
{
public int i;
public int[] arr = new int[10];
public void fun(int i, int val)
{
arr[i] = val;
}
}
class Program
{
static void Main(string[] args)
{
sample s = new sample();
s.i = 10;
sample.fun(1, 5);
s.fun(1, 5);
Console.ReadLine();
}
}
a. sample.fun(1, 5) will not work correctly
b. s.i = 10 cannot work as i is ‘public’
c. sample.fun(1, 5) will set value as 5 in arr[1].
d. s.fun(1, 5) will work correctly

Output from following set of code?


class sample
{
int i;
double k;
public sample(int ii, double kk)
{
i = ii;
k = kk;
double j = (i) + (k);
Console.WriteLine(j);
}
~sample()
{
double j = i - k;
Console.WriteLine(j);
}
}
class Program
{
static void Main(string[] args)
{
sample s = new sample(8, 2.5);
Console.ReadLine();
}
}
a. 0 0
89
b. 10.5 0
c. Compile time error
d. 10.5 5.5

Output from selective set of code is:


class box
{
public int volume;
int width;
int height;
int length;
public box(int w, int h, int l)
{
this.width = w;
this.height = h;
this.length = l;
}
~box()
{
volume = this.width * this.length * this.height;
console.writeline(volume);
}
}
class Program
{
public static void Main(string[] args)
{
box b = new box(4, 5, 9);
Console.ReadLine();
}
}
a. 0
b. Code executes successfully but prints nothing
c. Compile time error
d. 180

Which of these is used as default for a member of a class if no access specifier is used
for it?
a. private
b. public
c. protected internal
d. protected

90
Which of these access specifiers must be used for class so that it can be inherited by
another sub class?
a. public
b. private
c. both public & private
d. none of the mentioned

When you have finished defining a class, you may then create as many instances of the
class as you need using the new keyword.
True
False

Inheritance is the ability to create a new class from an existing class.


True
False

Which of the following is true about try block in C#?


A - A try block identifies a block of code for which particular exceptions is activated.
B - It is followed by one or more catch blocks.
C - Both of the above.
D - None of the above.

Which of the following is the correct about static member variables of a class?
A - We can define class members variables as static using the static keyword.
B - When we declare a member of a class as static, it means no matter how many
objects of the class are created, there is only one copy of the static member.
C - Both of the above.
D - None of the above.

91
The finally block is used to execute a given set of statements, whether an exception is
thrown or not thrown.
A - True
B - False

What would be output for the set of code?


using System;
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();
}
}
a) 4, 3.5
b) 8, 0
c) 7.5, 8
d) 8, 7

92
What will be the output of the given set of code?
using System;
class maths
{
public int length;
public int breadth;
public maths(int x, int y)
{
length = x;
breadth = y;
Console.WriteLine(x + y);
}
public maths(double x, int y)
{
length = (int)x;
breadth = y;
Console.WriteLine(x * y);
}
}
class Program
{
static void Main(string[] args)
{
maths m = new maths(20, 40);
maths k = new maths(12.0, 12);
Console.ReadLine();
}
}
a)
60
24
b)
60
0
c)
60
144
d)
60
144.0

93
What will be the output of the given set of code?
using System;
class maths
{
public int length;
public int breadth;
public maths(int x)
{
length = x + 1;
}
public maths(int x, int y)
{
length = x + 2;
}
}
class Program
{
static void Main(string[] args)
{
maths m = new maths(6);
maths k = new maths(6, 2);
Console.WriteLine(m.length);
Console.WriteLine(k.length);
Console.ReadLine();
}
}

a)
8
8
b)
0
2
c)
8
10
d)
7
8

94
What will be the output of the given set of code?
using System;
class maths
{
public maths()
{
Console.WriteLine("constructor 1 :");
}
public maths(int x)
{
int p = 2;
int u;
u = p + x;
Console.WriteLine("constructor 2: " + u);
}
}
class Program
{
static void Main(string[] args)
{
maths k = new maths(4);
maths t = new maths();
Console.ReadLine();
}
}

a)
constructor 1:
constructor 2: 6
b)
constructor 2: 6
constructor 2: 6
c)
constructor 2: 6
constructor 1:
d) None of the mentioned

What will be the output of the given set of code?


using System;
class maths
{
int i;
public maths(int x)
{
i = x;
Console.WriteLine("hello");
}

95
}
class maths1 : maths
{
public maths1(int x) : base(x)
{
Console.WriteLine("bye");
}
}
class Program
{
static void Main(string[] args)
{
maths1 k = new maths1(12);
Console.ReadLine();
}
}

a)
hello
bye
b)
12
hello
c)
bye
12
d) Compile time error

What will be the output of the given set of code?


using System;
class maths
{
int i;
public maths(int ii)
{
ii = 12;
int j = 12;
int r = ii * j;
Console.WriteLine(r);
}
}
class maths1 : maths
{
public maths1(int u) : base(u)
{
u = 13;
int h = 13;
Console.WriteLine(u + h);

96
}
}
class maths2 : maths1
{
public maths2(int k) : base(k)
{
k = 24;
int o = 6;
Console.WriteLine(k / o);
}
}
class Program
{
static void Main(string[] args)
{
maths2 t = new maths2(10);
Console.ReadLine();
}
}
a)
4
26
144
b)
26
4
144
c)
144
26
4
d)
0
0
0

Correct statement about constructor overloading in C# is?


a) Overloaded constructors have the same name as the class
b) Overloaded constructors cannot use optional arguments

97
c) Overloaded constructors can have different type of number of arguments as well as
differ in number of arguments
d) All of above mentioned

What will be the output of the given set of code?


using System;
class maths
{
static maths()
{
int s = 8;
Console.WriteLine(s);
}
public maths(int f)
{
int h = 10;
Console.WriteLine(h);
}
}
class Program
{
static void Main(string[] args)
{
maths p = new maths(0);
Console.ReadLine();
}
}

a)
10
10
b)
0
10
c)
8
10
d)
8
8

98
What will be the output of the given set of code?
using System;
class maths
{
int i;
public maths(int ii)
{
ii = -25;
int g;
g = ii > 0? ii : ii * -1;
Console.WriteLine(g);
}
}
class maths1 : maths
{
public maths1(int ll) : base(ll)
{
ll = -1000;
Console.WriteLine((ll > 0? ll : ll * -1));
}
}
class Program
{
static void Main(string[] args)
{
maths1 p = new maths1(6);
Console.ReadLine();
}
}

a)
-25
-1000
b)
-1000
-25
c)
25
1000
d) None of the mentioned

99
The following set of code is run on single level of inheritance. Find correct statement
about the code?
using System;
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();
}
}
a) 10, 20, 30
base method
b) 10, 20, 0
c) compile time error
d) base method

Correct statement about the following C# code is?


using System;
class baseclass
{
int a;
public baseclass(int a1)
{
a = a1;
Console.WriteLine(" a ");
}
class derivedclass : baseclass
{
public derivedclass(int a1) : base(a1)

100
{
Console.WriteLine(" b ");
}
}
class program
{
static void main(string[] args)
{
derivedclass d = new derivedclass(20);
}
}
}

a) Compile time error


b)
b
a
c)
a
b
d) the program will work correctly if we replace base(a1) with base.baseclass(a1)

What would be output for the set of code?


using System;
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

101
{
static void Main(string[] args)
{
maths obj = new maths();
int a = 4;
double b = 3.4;
obj.add(a, a);
obj.add(b, b);
Console.WriteLine(obj.x + " " + obj.y);
Console.ReadLine();
}
}
A. 4 3.5
B. 8 0
C. 7.5 8
D. 8, 6.8

What will be the output for the given set of code?


using System;
class A
{
public int i;
public void display()
{
Console.WriteLine(i);
}
}
class B : A
{
public int j;
public void display()
{
Console.WriteLine(j);
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B();
obj.i = 1;
obj.j = 2;
obj.display();
Console.ReadLine();
}
}
A. 0
B. 2
C. 1
D. Compile time error

102
What will be the correct output for the given code snippet?
using System;
class maths
{
public int fact(int n)
{
int result;
if (n == 1)
return 1;
result = fact(n - 1) * n;
return result;
}
}
class Output
{
static void Main(string[] args)
{
maths obj = new maths();
Console.WriteLine(obj.fact(4) * obj.fact(2));
}
}
A. 64
B. 60
C. 120
D. 48

Find any errors in the following BankAccount constructor


public int BankAccount()
{
balance = 0;
}
name
formal parameters
return type
syntax error

Can you overload a function with the same number and types of arguments
(parameters) but with a different return type?
Yes
No
Yes, but only if function is static
Yes, but only if function is virtual

103
There are two types of constructors in C#:
Default
Built in
Parameterized
Both a and c

A default constructor is ______.


parameterless
easy to use
convenient
inconvenient

The process of defining two or more methods within the same class that have same
name but different parameters list is
method overloading
method overriding
encapsulation
inheritance

Which of the following best defines a class?


a) Parent of an object
b) Instance of an object
c) Blueprint of an object
d) Scope of an object

Which feature of OOP illustrated the code reusability?


a) Polymorphism
b) Abstraction
c) Encapsulation
d) Inheritance

104
How many classes can be defined in a single program?
a) Only 1
b) Only 100
c) Only 999
d) As many as you want

If a function can perform more than 1 type of tasks, where the function name remains
same, which feature of OOP is used here?
a) Encapsulation
b) Inheritance
c) Polymorphism
d) Abstraction

Which feature in OOP is used to allocate additional function to a predefined operator


in any language?
a) Operator Overloading
b) Function Overloading
c) Operator Overriding
d) Function Overriding

Which syntax for class definition is wrong?


a) class student{ }
b) student class{ }
c) class student{ public student(int a){ } }
d) class student{ student(int a){} }

Which among the following best describes polymorphism?


a) It is the ability for a message/data to be processed in more than one form
b) It is the ability for a message/data to be processed in only 1 form
c) It is the ability for many messages/data to be processed in one way
d) It is the ability for undefined message/data to be processed in at least one way

105
If same message is passed to objects of several different classes and all of those can
respond in a different way, what is this feature called?
a) Inheritance
b) Overloading
c) Polymorphism
d) Overriding

Which among the following is not a necessary condition for constructors?


a) Its name must be same as that of class
b) It must not have any return type
c) It must contain a definition body
d) It can contains arguments

How many types of constructors are available for use in general (with respect to
parameters)?
a) 2
b) 3
c) 4
d) 5

Default constructor must be defined, if parameterized constructor is defined and the


object is to be created without arguments.
a) True
b) False

For constructor overloading, each constructor must differ in ___________ and


__________
a) Number of arguments and type of arguments
b) Number of arguments and return type
c) Return type and type of arguments
d) Return type and definition

106
Which constructor is called while assigning some object with another?
a) Default
b) Parameterized
c) Copy
d) Direct assignment is used

Which type of constructor can’t have a return type?


a) Default
b) Parameterized
c) Copy
d) Constructors don’t have a return type

Which among the following best describes constructor overloading?


a) Defining one constructor in each class of a program
b) Defining more than one constructor in single class
c) Defining more than one constructor in single class with different signature
d) Defining destructor with each constructor

Which among the following is false for a constructor?


a) Constructors doesn’t have a return value
b) Constructors are always user defined
c) Constructors are overloaded with different signature
d) Constructors may or may not have any arguments being accepted

When is the constructor called for an object?


a) As soon as overloading is required
b) As soon as class is derived
c) As soon as class is created
d) As soon as object is created

Why do we use constructor overloading?


a) To use different types of constructors
b) Because it’s a feature provided

107
c) To initialize the object in different ways
d) To differentiate one constructor from another

If programmer have defined parameterized constructor only, then ____________.


a) Default constructor will not be created by the compiler implicitly
b) Default constructor will be created by the compiler implicitly
c) Default constructor will not be created but called at runtime
d) Compile time error

Which constructor will be called from the object obj2 in the following program?
class A
{
int i;
public A()
{
i = 0;
}
public A(int x)
{
i = x + 1;
}
public A(int y, int x)
{
i = x + y;
}
}
A obj1= new A(10);
A obj2= new A(10, 20);
A obj3;
a) A(int x)
b) A(int y)
c) A(int y, int x)
d) A(int y; int x)

Which is correct syntax?


a) classname objectname= new() integer;
b) classname objectname= new classname;
c) classname objectname= new classname();
d) classname objectname= new() classname();

108
Which among the following can restrict class members to get inherited?
a) private
b) protected
c) public
d) All of above

Which specifier allows a programmer to make the private members which can be
inherited?
a) private
b) default
c) protected
d) protected and default

If a function has to be called only by using other member functions of the class, what
should be the access specifier used for that function?
a) private
b) protected
c) public
d) default

If members of a super class are public, then________


a) All those will be available in subclasses
b) None of those will be available in subclasses
c) Only data members will be available in subclass
d) Only member functions will be available in subclass

How to access members of the class inside a member function?


a) Using this keyword only
b) Using dot operator
c) Using arrow operator
d) Used directly or with this keyword

109
Member function of a class can ____________
a) Access all the members of the class
b) Access only public members of the class
c) Access only the private members of the class
d) Access subclass members

Which member function doesn’t require any return type?


a) Static
b) Constructor
c) Const
d) Inline

A base class is also known as _____________ class.


a) Basic
b) Inherited
c) Super
d) Sub

Class is _____________ of an object.


a) Basic function definition
b) Detailed description with values
c) Blueprint
d) Set of constant values

Which among the following is the most abstract form of class?


a) Cars
b) BMW cars
c) Big cars
d) Small cars

Which among the following is inherited by a derived class from base class?
a) Data members only
b) Member functions only

110
c) All the members except private members
d) All the members of base class

Which members can never be accessed in derived class from the base class?
a) private
b) protected
c) public
d) All except private

How many derived class can a single base class have?


a) 1
b) 2
c) 3
d) As many are required

Derived class is also known as ______________ class.


a) Subclass
b) Small class
c) Big class
d) Noticeable class

If a base class is inherited from another class and then one class derives it, which
inheritance is shown?
a) Multiple
b) Single
c) Hierarchical
d) Multi-level

Members which are not intended to be inherited are declared as ________________.


a) public members
b) protected members
c) private members
d) private or protected members

111
Which among the following is true?
a) C# supports all types of inheritance
b) C# supports multiple inheritance
c) C# doesn’t support multiple inheritance
d) C# doesn’t support inheritance

Which keyword is used to declare virtual functions?


a) virtual
b) virt
c) anonymous
d) virtually

Where the virtual function should be defined?


a) Twice in base class
b) Derived class
c) Base class and derived class
d) Base class

In which access specifier should a virtual function be defined?


a) Private
b) Public
c) Protected
d) Default

Which among the following is true for virtual functions?


a) Prototype must be different in base and derived class
b) Prototype must be same in base class and derived class
c) Prototype must be given only in base class
d) Prototype must have different signature in base and derived class

The virtual functions must be declared and defined in _____________ class and
overridden in ___________ class.
a) base, base

112
b) derived, derived
c) derived, base
d) base, derived

Methods can be overloaded in C# by _________


a) specifying different return types.
b) specifying different names for the methods.
c) specifying different number of parameters
d) None of the above

Which of the following sentences are true about Constructors?


a) The constructor can have the same name as that of its class.
c) The constructor may or may not have name same as that of the name of its class.
b) The constructor can have the same name as one of the methods in the class.
d) The constructor must have the same name as that of the name of its class.

The concept of derived classes is involved in


inheritance.
encapsulation.
data hiding.
abstract data types.

A member function
is always public
is always private
can be public or private
cannot be defined.

What does the keyword virtual mean in the method definition?


The method is public
The method can be derived
The method is static
The method can be overridden

113
A private class data members can be accessed ___________.
from its child class
from outside the class
from that class only
both from outside and child class

114

You might also like