OOP - Tieng Anh
OOP - Tieng Anh
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
1
C. base
D. extend
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);
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
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
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;
7
C# provides feature of method overloading which means methods with same name but
different types and arguments.
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
"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
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
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
Which of the following is the default access modifier of the class members?
public
private
internal
protected internal
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
14
Properties provide the opportunity to protect a field in a class by reading and writing
to it using accessors.
a) True
b) False
15
b) getNumber() method must declare a body because it is not marked abstract.
d) None of the above.
16
What error does the following code generates when compiled?
abstract class ClassB
{
private abstract void getNumber();
}
class ClassA : ClassB
{ }
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 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
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
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
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));
}
}
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);
}
}
}
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
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);
}
}
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);
}
}
}
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.
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");
}
}
}
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
C# is a ____________language.
a) purely Procedure-Oriented
b) Procedure-Oriented and Object-Oriented
c) partially Procedure-Oriented
d) purely Object-Oriented
29
In C#, datatypes are divided into two fundamental categories: value types and
reference types.
a) True
b) False
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
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
C# supports inheritance?
1. Yes
2. No
3. Sometime
4. Don’t know
32
We can make a property WriteOnly by:
1. Removing Set accessor
2. Removing Get accessor
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
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
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
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 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
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.
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
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
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
42
8
b) 0
2
c) 8
10
d) 7
8
43
}
}
a) CSharp
b) Java
c) Run time error
d) CSharp 0
a) A
b) B
c) Compile time error
d) Run time error
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 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.
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
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;
}
}
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
Two methods with the same name but with different parameters.
A. Overloading
B. Multiplexing
C. Duplexing
D. Loading
51
D. No errors
52
Methods are used to represent:
a.) actions
b.) classes
c.) data
d.) instances
53
When using encapsulation how should data be shared with external code?
a.) Public variables
b.) Methods
c.) Properties
d.) Private variables
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.
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
55
[C] abstract
[D] struct
56
The class which derives the properties of another class is called _________ class.
[A] derived
[B] base
[C] derivation
[D] basic
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
57
C. private
D. public
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
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)
{
}
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 is correct about the C# code snippet given below?
namespace CompSciBitsConsoleApplication
{
class Sample
{
public int index;
public int[] arr = new int[10];
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
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
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
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);
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
69
Which of these base class are accessible to the derived class members?
a. static
b. protected
c. private
d. shared
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
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
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
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();
a) 2 1
b) 1 0
75
c) 0 2
d) 1 2
a) 1, 3
b) 2, 3
c) 1, 2
d) compile time error
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
The ______ method is used to assign some value to a data member in a class.
a) value c) get
b) set d) find
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.
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
Two methods with the same name but with different parameters.
Overloading
Loading
Multiplexing
Duplexing
80
public
private
protected
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
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
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
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
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)
86
[C] ArrayOutofBounds
[D] IncorrectArithmeticOverflow
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
87
Abstract class contains _____.
A. Abstract methods
B. Non abstract methods
C. Both
D. None
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
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
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
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
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
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
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
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
100
{
Console.WriteLine(" b ");
}
}
class program
{
static void main(string[] args)
{
derivedclass d = new derivedclass(20);
}
}
}
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
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
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
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
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
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
How many types of constructors are available for use in general (with respect to
parameters)?
a) 2
b) 3
c) 4
d) 5
106
Which constructor is called while assigning some object with another?
a) Default
b) Parameterized
c) Copy
d) Direct assignment is used
107
c) To initialize the object in different ways
d) To differentiate one constructor from another
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)
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
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 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
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
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
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
A member function
is always public
is always private
can be public or private
cannot be defined.
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