You are on page 1of 66

Object Oriented Programming

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-


computer-science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php

1. Questions and Answers – OOPs Basic Concepts


This set of Object Oriented Programming online test focuses on “OOP Basic Concepts”.

1. Which was the first purely object oriented programming language developed?

a) Java

b) C++

c) SmallTalk

d) Kotlin

View Answer

Answer: c

Explanation: SmallTalk was the first programming language developed which was purely object oriented.
It was developed by Alan Kay. OOP concept came into picture in 1970’s.

2. 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

View Answer

Answer: b

Explanation: A class is Blueprint of an object which describes/ shows all the functions and data that are
provided by an object of a specific class. It can’t be called as parent or instance of an object. Class in
general describes all the properties of an object.
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
3. Who invented OOP?

a) Alan Kay

b) Andrea Ferro

c) Dennis Ritchie

d) Adele Goldberg

View Answer

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-


computer-science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php

Answer: a

Explanation: Alan Kay invented OOP, Andrea Ferro was a part of SmallTalk Development. Dennis
invented C++ and Adele Goldberg was in team to develop SmallTalk but Alan actually had got rewarded
for OOP.

4. What is the additional feature in classes that was not in structures?

a) Data members

b) Member functions

c) Static data allowed

d) Public access specifier

View Answer

Answer: b

Explanation: Member functions are allowed inside a class but were not present in structure concept. Data
members, static data and public access specifiers were present in structures too.

5. Which is not feature of OOP in general definitions?

a) Code reusability

b) Modularity

c) Duplicate/Redundant data

d) Efficient Code
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
View Answer

Answer: c

Explanation: Duplicate/Redundant data is dependent on programmer and hence can’t be guaranteed by


OOP. Code reusability is done using inheritance. Modularity is supported by using different code files
and classes. Codes are more efficient because of features of OOP.

6. Pure OOP can be implemented without using class in a program. (True or False)

a) True

b) False

View Answer

Answer: b

Explanation: It’s false because for a program to be pure OO, everything must be written inside classes. If
this rule is violated, the program can’t be labelled as purely OO.

7. Which Feature of OOP illustrated the code reusability?

a) Polymorphism

b) Abstraction

c) Encapsulation

d) Inheritance

View Answer

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-


computer-science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php

Answer: d

Explanation: Using inheritance we can reuse the code already written and also can avoid creation of many
new functions or variables, as that can be done one time and be reused, using classes.

8. Which language does not support all 4 types of inheritance?

a) C++

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
b) Java

c) Kotlin

d) Small Talk

View Answer

Answer: b

Explanation: Java doesn’t support all 4 types of inheritance. It doesn’t support multiple inheritance. But
the multiple inheritance can be implemented using interfaces in Java.

9. 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

View Answer

Answer: d

Explanation: Any number of classes can be defined inside a program, provided that their names are
different. In java, if public class is present then it must have the same name as that of file.

10. When OOP concept did first came into picture?

a) 1970’s

b) 1980’s

c) 1993

d) 1995

View Answer

Answer: a

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Explanation: OOP first came into picture in 1970’s by Alan and his team. Later it was used by some
programming languages and got implemented successfully, SmallTalk was first language to use pure
OOP and followed all rules strictly.

11. Why Java is Partially OOP language?

a) It supports usual declaration of primitive data types

b) It doesn’t support all types of inheritance

c) It allows code to be written outside classes

d) It does not support pointers

View Answer

Answer: a

Explanation: As Java supports usual declaration of data variables, it is partial implementation of OOP.
Because according to rules of OOP, object constructors must be used, even for declaration of variables.

12. Which concept of OOP is false for C++?

a) Code can be written without using classes

b) Code must contain at least one class

c) A class must have member functions

d) At least one object should be declared in code

View Answer

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-


computer-science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php

Answer: b

Explanation: In C++, it’s not necessary to use classes, and hence codes can be written without using OOP
concept. Classes may or may not contain member functions, so it’s not a necessary condition in C++.
And, an object can only be declared in a code if its class is defined/included via header file.

advertisement

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
13. Which header file is required in C++ to use OOP?

a) iostream.h

b) stdio.h

c) stdlib.h

d) OOP can be used without using any header file

View Answer

Answer: d

Explanation: We need not include any specific header file to use OOP concept in C++, only specific
functions used in code need their respective header files to be included or classes should be defined if
needed.

14. Which of the two features match each other?

a) Inheritance and Encapsulation

b) Encapsulation and Polymorphism

c) Encapsulation and Abstraction

d) Abstraction and Polymorphism

View Answer

Answer: c

Explanation: Encapsulation and Abstraction are similar features. Encapsulation is actually binding all the
properties in a single class or we can say hiding all the features of object inside a class. And Abstraction
is hiding unwanted data (for user) and showing only the data required by the user of program.

15. Which feature allows open recursion, among the following?

a) Use of this pointer

b) Use of pointers

c) Use of pass by value

d) Use of parameterized constructor

View Answer
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Answer: a

Explanation: Use of this pointer allows an object to call data and methods of itself whenever needed. This
helps us call the members of an object recursively, and differentiate the variables of different scopes.

2. Questions and Answers – Classes


This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Classes”.

1. Which of the following is not type of class?

a) Abstract Class

b) Final Class

c) Start Class

d) String Class

View Answer

Answer: c

Explanation: Only 9 types of classes are provided in general, namely, abstract, final, mutable, wrapper,
anonymous, input-output, string, system, network. We may further divide the classes into parent class and
subclass if inheritance is used.

2. Class is pass by _______

a) Value

b) Reference

c) Value or Reference, depending on program

d) Copy

View Answer

Answer: b

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Explanation: Classes are pass by reference, and the structures are pass by copy. It doesn’t depend on
program.

3. What is default access specifier for data members or member functions declared within a class
without any specifier, in C++ ?

a) Private

b) Protected

c) Public

d) Depends on compiler

View Answer

Answer: a

Explanation: The data members and member functions are Private by default in C++ classes, if none of
the access specifier is used. It is actually made to increase the privacy of data.

4. Which is most appropriate comment on following class definition :

class Student

int a;

public : float a;

};

a) Error : same variable name can’t be used twice

b) Error : Public must come first

c) Error : data types are different for same variable

d) It is correct

View Answer

Answer: a

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Explanation: Same variable can’t be defined twice in same scope. Even if the data types are different,
variable name must be different. There is no rule like Public member should come first or last.

5. Which is known as generic class?

a) Abstract class

b) Final class

c) Template class

d) Efficient Code

View Answer

Answer: c

Explanation: Template classes are known to be generic classes because those can be used for any data
type value and the same class can be used for all the variables of different data types.

6. Size of a class is :

a) Sum of size of all the variables declared inside the class

b) Sum of size of all the variables along with inherited variables in the class

c) Size of largest size of variable

d) Classes doesn’t have any size

View Answer

Answer: d

Explanation: Classes doesn’t have any size, actually the size of object of the class can be defined. That is
done only when an object is created and its constructor is called.

7. Which class can have member functions without their implementation?

a) Default class

b) String class

c) Template class

d) Abstract class

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
View Answer

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-


computer-science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php

Answer: d

Explanation: Abstract classes can have member functions with no implementation, where the inheriting
subclasses must implement those functions.

8. Which of the following describes a friend class?

a) Friend class can access all the private members of the class, of which it is a friend

b) Friend class can only access protected members of the class, of which it is a friend

c) Friend class don’t have any implementation

d) Friend class can’t access any data member of another class but can use it’s methods

View Answer

Answer: a

Explanation: A friend class can access all the private members of another class, of which it is friend. It is
a special class provided to use when you need to reuse the data of a class but don’t want that class to have
those special functions.

9. What is scope of a class nested inside another class?

a) Protected scope

b) Private scope

c) Global scope

d) Depends on access specifier and inheritance used

View Answer

Answer: d

Explanation: It depends on the access specifier and the type of inheritance used with the class, because if
the class is inherited then the nested class can be used by subclass too, provided it’s not of private type.

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
10. Class with main() function can be inherited (True/False)

a) True

b) False

View Answer

Answer: a

Explanation: The class containing main function can be inherited and hence the program can be executed
using the derived class names also in java.

advertisement

11. Which among the following is false, for member function of a class?

a) All member functions must be defined

b) Member functions can be defined inside or outside the class body

c) Member functions need not be declared inside the class definition

d) Member functions can be made friend to another class using friend keyword

View Answer

Answer: c

Explanation: Member functions must be declared inside class body, thought the definition can be given
outside the class body. There is no way to declare the member functions inside the class.

12. 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){} };

View Answer

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Answer: b

Explanation: Keyword class should come first. Class name should come after keyword class.
Parameterized constructor definition depends on programmer so it can be left empty also.

13. Which of the following pairs are similar?

a) Class and object

b) Class and structure

c) Structure and object

d) Structure and functions

View Answer

Answer: b

Explanation: Class and structure are similar to each other. Only major difference is that a structure
doesn’t have member functions whereas the class can have both data members and member functions.

14. Which among the following is false for class features?

a) Classes may/may not have both data members and member functions

b) Class definition must be ended with a colon

c) Class can have only member functions with no data members

d) Class is similar to union and structures

View Answer

Answer: b

Explanation: Class definition must end with a semicolon, not colon. Class can have only member
functions in its body with no data members.

15. Instance of which type of class can’t be created?

a) Anonymous class

b) Nested class

c) Parent class

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
d) Abstract class

View Answer

Answer: d

Explanation: Instance of abstract class can’t be created as it will not have any constructor of its own,
hence while creating an instance of class, it can’t initialize the object members. Actually the class
inheriting the abstract class can have its instance, because it will have implementation of all members.

3. Questions and Answers – Objects


This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Objects”.

1. Which definition best describes an object?

a) Instance of a class

b) Instance of itself

c) Child of a class

d) Overview of a class

View Answer

Answer: a

Explanation: An object is instance of its class. It can be declared in the same way that a variable is
declared, only thing is you have to use class name as the data type.

2. How many objects can be declared of a specific class in a single program?

a) 32768

b) 127

c) 1

d) As many as you want

View Answer

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Answer: d

Explanation: You can create as many objects of a specific class as you want, provided enough memory is
available.

3. Which among the following is false?

a) Object must be created before using members of a class

b) Memory for an object is allocated only after its constructor is called

c) Objects can’t be passed by reference

d) Objects size depends on its class data members

View Answer

Answer: c

Explanation: Objects can be passed by reference. Objects can be passed by value also. If object of a class
is not created, we can’t use members of that class.

4. Which of the following is incorrect?

a) class student{ }s;

b) class student{ }; student s;

c) class student{ }s[];

d) class student{ }; student s[5];

View Answer

Answer: c

Explanation: The array must be specified with a size. You can’t declare object array, or any other linear
array without specifying its size. It’s a mandatory field.

5. The object can’t be:

a) Passed by reference

b) Passed by value

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
c) Passed by copy

d) Passed as function

View Answer

Answer: d

Explanation: Object can’t be passed as function as it is an instance of some class, it’s not a function.
Object can be passed by reference, value or copy. There is no term defined as pass as function for objects.

6. What is size of the object of following class (64 bit system)?

class student { int rollno; char name[20]; static int studentno; };

a) 20

b) 22

c) 24

d) 28

View Answer

Answer: c

Explanation: The size of any object of student class will be of size 4+20=24, because static members are
not really considered as property of a single object. So static variables size will not be added.

7. Functions can’t return objects. (True/False)

a) True

b) False

View Answer

Answer: b

Explanation: Functions can always return an object if the return type is same as that of object being
returned. Care has to be taken while writing the prototype of function.

8. How members of an object are accessed?

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
a) Using dot operator/period symbol

b) Using scope resolution operator

c) Using member names directly

d) Using pointer only

View Answer

Answer: a

Explanation: Using dot operator after the name of object we can access its members. It is not necessary to
use the pointers. We can’t use the names directly because it may be used outside the class.

9. If a local class is defined in a function, which of the following is true for an object of that class?

a) Object is accessible outside the function

b) Object can be declared inside any other function

c) Object can be used to call other class members

d) Object can be used/accessed/declared locally in that function.

View Answer

Answer: d

Explanation: For an object which belongs to a local class, it is mandatory to declare and use the object
within the function because the class is accessible locally within the class only.

10. Which among the following is wrong?

a) class student{ }; student s;

b) abstract class student{ }; student s;

c) abstract class student{ }s[50000000];

d) abstract class student{ }; class toppers: public student{ }; topper t;

View Answer

Answer: b

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Explanation: We can never create instance of an abstract class. Abstract classes doesn’t have constructors
and hence when an instance is created there is no facility to initialize its members. Option d is correct
because topper class is inheriting the base abstract class student, and hence topper class object can be
created easily.

11. Object declared in main() function:

a) Can be used by any other function

b) Can be used by main() function of any other program

c) Can’t be used by any other function

d) Can be accessed using scope resolution operator

View Answer

Answer: c

Explanation: The object declared in main() have local scope inside main() function only. It can’t be used
outside main() function. Scope resolution operator is used to access globally declared variables/objects.

12. When an object is returned___________

a) A temporary object is created to return the value

b) The same object used in function is used to return the value

c) The Object can be returned without creation of temporary object

d) Object are returned implicitly, we can’t say how it happens inside program

View Answer

Answer: a

Explanation: A temporary object is created to return the value. It is created because object used in
function is destroyed as soon as the function is returned. The temporary variable returns the value and
then gets destroyed.

advertisement

13. Which among the following is correct?

a) class student{ }s1,s2; s1.student()=s2.student();


For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
b) class student{ }s1; class topper{ }t1; s1=t1;

c) class student{ }s1,s2; s1=s2;

d) class student{ }s1; class topper{ }t1; s1.student()=s2.topper();

View Answer

Answer: c

Explanation: Only if the objects are of same class then their data can be copied from to another using
assignment operator. This actually comes under operator overloading. Class constructors can’t be
assigned any explicit value as in option b and d.

14. Which among following is correct for initializing the class below?

class student{

int marks;

int cgpa;

public: student(int i, int j){

marks=I;

cgpa=j

};

a) student s[3]={ s(394, 9); s(394, 9); s(394,9); };

b) student s[2]={ s(394,9), s(222,5) };

c) student s[2]={ s1(392,9), s2(222,5) };

d) student s[2]={ s[392,9], s2[222,5] };

View Answer

Answer: b

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Explanation: It is the way we can initialize the data members for an object array using parameterized
constructor. We can do this to pass our own intended values to initialize the object array data.

15. Object can’t be used with pointers because they belong to user defined class, and compiler can’t
decide the type of data may be used inside the class. (True/False)

a) True

b) False

View Answer

Answer: b

Explanation: The explanation given is wrong because object can always be used with pointers like with
any other variables. Compiler doesn’t have to know the structure of the class to use a pointer because the
pointers only points to a memory address/stores that address.

4. Questions and Answers – OOPs Features


This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “OOP Features”.

1. Which feature of OOP indicates code reusability?

a) Encapsulation

b) Inheritance

c) Abstraction

d) Polymorphism

View Answer

Answer: b

Explanation: Inheritance indicates the code reusability. Encapsulation and abstraction are meant to
hide/group data into one element. Polymorphism is to indicate different tasks performed by a single
entity.

2. If a function can perform more than 1 type of tasks, where the function name remains same,
which feature of OOP is used here?

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
a) Encapsulation

b) Inheritance

c) Polymorphism

d) Abstraction

View Answer

Answer: c

Explanation: For the feature given above, the OOP feature used is Polymorphism. Example of
polymorphism in real life is a kid, who can be a student, a son, a brother depending on where he is.

3. If different properties and functions of a real world entity is grouped or embedded into a single
element, what is it called in OOP language?

a) Inheritance

b) Polymorphism

c) Abstraction

d) Encapsulation

View Answer

Answer: d

Explanation: It is Encapsulation, which groups different properties and functions of a real world entity
into single element. Abstraction, on other hand, is hiding of functional or exact working of codes and
showing only the things which are required by the user.

4. Which of the following is not feature of pure OOP?

a) Classes must be used

b) Inheritance

c) Data may/may not be declared using object

d) Functions Overloading

View Answer

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Answer: c

Explanation: Data must be declared using objects. Object usage is mandatory because it in turn calls its
constructors, which in turn must have a class defined. If object is not used, it is violation of pure OOP
concept.

5. Which among the following doesn’t come under OOP concept?

a) Platform independent

b) Data binding

c) Message passing

d) Data hiding

View Answer

Answer: a

Explanation: Platform independence is not feature of OOP. C++ supports OOP but it’s not a platform
independent language. Platform independence depends on programming language.

6. Which feature of OOP is indicated by the following code?

class student{ int marks; };

class topper:public student{ int age; topper(int age){ this.age=age; } };

a) Inheritance

b) Polymorphism

c) Inheritance and polymorphism

d) Encapsulation and Inheritance

View Answer

Answer: d

Explanation: Encapsulation is indicated by use of classes. Inheritance is shown by inheriting the student
class into topper class. Polymorphism is not shown here because we have defined the constructor in
topper class but that doesn’t mean that default constructor is overloaded.

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
7. Which feature may be violated if we don’t use classes in a program?

a) Inheritance can’t be implemented

b) Object must be used is violated

c) Encapsulation only is violated

d) Basically all the features of OOP gets violated

View Answer

Answer: d

Explanation: All the features are violated because Inheritance and Encapsulation won’t be implemented.
Polymorphism and Abstraction is still possible in some cases, but the main features like data binding,
object use and etc won’t be used hence use of class is must for OOP concept.

8. How many basic features of OOP are required for a programming language to be purely OOP?

a) 7

b) 6

c) 5

d) 4

View Answer

Answer: a

Explanation: There are 7 basic features that define whether a programing language is pure OOP or not.
The 4 basic features are inheritance, polymorphism, encapsulation and abstraction. Further, one is, object
use is must, secondly, message passing and lastly, Dynamic binding.

9. The feature by which one object can interact with another object is:

a) Data transfer

b) Data Binding

c) Message Passing

d) Message reading

View Answer
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Answer: c

Explanation: The interaction between two object is called message passing feature. Data transfer is not
feature of OOP. Also, message reading is not feature of OOP.

10. ___________ underlines the feature of Polymorphism in a class.

a) Nested class

b) Enclosing class

c) Inline function

d) Virtual Function

View Answer

Answer: d

Explanation: Virtual Functions can be defined in any class using the keyword virtual. All the classes
which inherit the class containing the virtual function, define the virtual function as required. Redefining
the function on all the derived classes according to class and use represents polymorphism.

advertisement

11. 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

View Answer

Answer: a

Explanation: The feature is operator overloading. There is not feature named operator overriding
specifically. Function overloading and overriding doesn’t give addition function to any operator.

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
12. Which among doesn’t illustrates polymorphism?

a) Function overloading

b) Function overriding

c) Operator overloading

d) Virtual function

View Answer

Answer: b

Explanation: Function overriding doesn’t illustrate polymorphism because the functions are actually
different and theirs scopes are different. Function and operator overloading illustrate proper
polymorphism. Virtual functions show polymorphism because all the classes which inherit virtual
function, define the same function in different ways.

13. Exception handling is feature of OOP. (True/False)

a) True

b) False

View Answer

Answer: a

Explanation: Exception handling is feature of OOP as it includes classes concept in most of the cases.
Also it may come handy while using inheritance.

14. Which among the following, for a pure OOP language, is true?

a) The language should follow 3 or more features of OOP

b) The language should follow at least 1 feature of OOP

c) The language must follow only 3 features of OOP

d) The language must follow all the rules of OOP

View Answer

Answer: d
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Explanation: The language must follow all the rules of OOP to be called a purely OOP language. Even if
a single OOP feature is not followed, then it’s known to be a partially OOP language.

15. OOP provides better security than POP:

a) Always true for any programming language

b) May not be true with respect to all programming languages

c) It depends on type of program

d) It’s vice-versa is true

View Answer

Answer: a

Explanation: It is always true as we have the facility of private and protected access specifiers. Also, only
the public and global data is available globally or else program should have proper permission to access
the private data.

5. Questions and Answers – Polymorphism


This set of Object-Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Polymorphism”.

1. 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

View Answer

Answer: a

Explanation: It is actually the ability for a message / data to be processed in more than one form. The
word polymorphism indicates many-forms. So if a single entity takes more than one form, it is known as
polymorphism.

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
2. What do you call the languages that support classes but not polymorphism?

a) Class based language

b) Procedure Oriented language

c) Object-based language

d) If classes are supported, polymorphism will always be supported

View Answer

Answer: c

Explanation: The languages which support classes but doesn’t support polymorphism, are known as
object-based languages. Polymorphism is such an important feature, that is a language doesn’t support
this feature, it can’t be called as a OOP language.

3. Which among the following is the language which supports classes but not polymorphism?

a) SmallTalk

b) Java

c) C++

d) Ada

View Answer

Answer: d

Explanation: Ada is the language which supports the concept of classes but doesn’t support the
polymorphism feature. It is an object-based programming language. Note that it’s not an OOP language.

4. 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

View Answer
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Answer: c

Explanation: The feature defined in question defines polymorphism feature. Here the different objects are
capable of responding to the same message in different ways, hence polymorphism.

5. Which class/set of classes can illustrate polymorphism in the following code:

abstract class student

public : int marks;

calc_grade();

class topper:public student

public : calc_grade()

return 10;

};

class average:public student

public : calc_grade()

return 20;

};

class failed{ int marks; };

a) Only class student can show polymorphism


For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
b) Only class student and topper together can show polymorphism

c) All class student, topper and average together can show polymorphism

d) Class failed should also inherit class student for this code to work for polymorphism

View Answer

Answer: c

Explanation: Since Student class is abstract class and class topper and average are inheriting student, class
topper and average must define the function named calc_grade(); in abstract class. Since both the
definition are different in those classes, calc_grade() will work in different way for same input from
different objects. Hence it shows polymorphism.

6. Which type of function among the following shows polymorphism?

a) Inline function

b) Virtual function

c) Undefined functions

d) Class member functions

View Answer

Answer: b

Explanation: Only virtual functions among these can show polymorphism. Class member functions can
show polymorphism too but we should be sure that the same function is being overloaded or is a function
of abstract class or something like this, since we are not sure about all these, we can’t say whether it can
show polymorphism or not.

7. In case of using abstract class or function overloading, which function is supposed to be called
first?

A) Local function

B) Function with highest priority in compiler

C) Global function

D) Function with lowest priority because it might have been halted since long time, because of low
priority

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
View Answer

Answer: b

Explanation: Function with highest priority is called. Here, it’s not about the thread scheduling in CPU,
but it focuses on whether the function in local scope is present or not, or if scope resolution is used in
some way, or if the function matches the argument signature. So all these things define which function
has the highest priority to be called in runtime. Local function could be one of the answer but we can’t
say if someone have used pointer to another function or same function name.

8. Which among the following can’t be used for polymorphism?

a) Static member functions

b) Member functions overloading

c) Predefined operator overloading

d) Constructor overloading

View Answer

Answer: a

Explanation: Static member functions are not property of any object. Hence it can’t be considered for
overloading/overriding. For polymorphism, function must be property of object, not only of class.

9. What is output of the following program?

class student

public : int marks;

void disp()

cout<<”its base class”

};

class topper:public student

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
{

public :

void disp()

cout<<”Its derived class”;

void main() { student s; topper t;

s.disp();

t.disp();

a) Its base classIts derived class

b) Its base class Its derived class

c) Its derived classIts base class

d) Its derived class Its base class

View Answer

Answer: a

Explanation: You need to focus on how the output is going to be shown, no space will be given after first
message from base class. And then the message from derived class will be printed. Function disp() in base
class overrides the function of base class being derived.

advertisement

10. Which among the following can show polymorphism?

a) Overloading ||

b) Overloading +=

c) Overloading <<

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
d) Overloading &&

View Answer

Answer: c

Explanation: Only insertion operator can be overloaded among all the given options. And the
polymorphism can be illustrated here only if any of these is applicable of being overloaded. Overloading
is type of polymorphism.

11. Find the output of the program:

class education

char name[10];

public : disp()

cout<<”Its education system”;

class school:public education

public: void dsip()

cout<<”Its school education system”;

};

void main()

school s;

s.disp();

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
}

a) Its school education system

b) Its education system

c) Its school education systemIts education system

d) Its education systemIts school education system

View Answer

Answer: a

Explanation: Notice that the function name in derived class is different from the function name in base
class. Hence when we call the disp() function, base class function is executed. No polymorphism is used
here.

12. Polymorphism is possible in C language.

a) True

b) False

View Answer

Answer: a

Explanation: It is possible to implement polymorphism in C language, even though it doesn’t support


class. We can use structures and then declare pointers which in turn points to some function. In this way
we simulate the functions like member functions but not exactly member function. Now we can overload
these functions, hence implementing polymorphism in C language.

13. Which problem may arise if we use abstract class functions for polymorphism?

a) All classes are converted as abstract class

b) Derived class must be of abstract type

c) All the derived classes must implement the undefined functions

d) Derived classes can’t redefine the function

View Answer

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Answer: c

Explanation: The undefined functions must be defined is a problem, because one may need to implement
few undefined functions from abstract class, but he will have to define each of the functions declared in
abstract class. Being useless task, it is a problem sometimes.

14. Which among the following is not true for polymorphism?

a) It is feature of OOP

b) Ease in readability of program

c) Helps in redefining the same functionality

d) Increases overhead of function definition always

View Answer

Answer: d

Explanation: It never increases function definition overhead, one way or another if you don’t use
polymorphism, you will use the definition in some other way, so it actually helps to write efficient codes.

15. If 2 classes derive one base class and redefine a function of base class, also overload some
operators inside class body. Among these two things of function and operator overloading, where is
polymorphism used?

a) Function overloading only

b) Operator overloading only

c) Both of these are using polymorphism

d) Either function overloading or operator overloading because polymorphism can be applied only
once in a program

View Answer

Answer: d

Explanation: Both of them are using polymorphism. It is not a necessary that polymorphism can be used
only once in a program, it can be used anywhere, any number of times in a single program.

6. Questions and Answers – Encapsulation


For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Encapsulation”.

1. Which among the following best describes encapsulation?

a) It is a way of combining various data members into a single unit

b) It is a way of combining various member functions into a single unit

c) It is a way of combining various data members and member functions into a single unit which can
operate on any data

d) It is a way of combining various data members and member functions that operate on those data
members into a single unit

View Answer

Answer: d

Explanation: It is a way of combining both data members and member functions, which operate on those
data members, into a single unit. We call it a class in OOP generally. This feature have helped us modify
the structures used in C language to be upgraded into class in C++ and other languages.

2. If data members are private, what can we do to access them from the class object?

a) Create public member functions to access those data members

b) Create private member functions to access those data members

c) Create protected member functions to access those data members

d) Private data members can never be accessed from outside the class

View Answer

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-


computer-science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php

Answer: a

Explanation: We can define public member functions to access those private data members and get their
value for use or alteration. They can’t be accessed directly but is possible to be access using member
functions. This is done to ensure that the private data doesn’t get modified accidentally.

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
3. While using encapsulation, which among the following is possible?

a) Code modification can be additional overhead

b) Data member’s data type can be changed without changing any other code

c) Data member’s type can’t be changed, or whole code have to be changed

d) Member functions can be used to change the data type of data members

View Answer

Answer: b

Explanation: Data member’s data type can be changed without changing any further code. All the
members using that data can continue in the same way without any modification. Member functions can
never change the data type of same class data members.

4. Which feature can be implemented using encapsulation?

a) Inheritance

b) Abstraction

c) Polymorphism

d) Overloading

View Answer

Answer: b

Explanation: Data abstraction can be achieved by using encapsulation. We can hide the operation and
structure of actual program from the user and can show only required information by the user.

5. Find which of the following uses encapsulation?

a) void main(){ int a; void fun( int a=10; cout<<a); fun(); }

b) class student{ int a; public: int b;};

c) class student{int a; public: void disp(){ cout<<a;} };

d) struct topper{ char name[10]; public : int marks; }

View Answer

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Answer: c

Explanation: It is the class which uses both the data members and member functions being declared inside
a single unit. Only data members can be there in structures also. And the encapsulation can only be
illustrated if some data/operations are associated within class.

6. Encapsulation helps in writing ___________ classes in java

a) Mutable

b) Abstract

c) Wrapper

d) Immutable

View Answer

Answer: d

Explanation: Immutable classes are used for caching purpose generally. And it can be created by making
the class as final and making all its members private.

7. Which among the following should be encapsulated?

a) The data which is prone to change is near future

b) The data prone to change in long terms

c) The data which is intended to be changed

d) The data which belongs to some other class

View Answer

Answer: a

Explanation: The data prone to change in near future is usually encapsulated so that it doesn’t get changed
accidentally. We encapsulate the data to hide the critical working of program from outside world.

8. How can Encapsulation be achieved?

a) Using Access Specifiers

b) Using only private members


For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
c) Using inheritance

d) Using Abstraction

View Answer

Answer: a

Explanation: Using access specifiers we can achieve encapsulation. Using this we can in turn implement
data abstraction. It’s not necessary that we only use private access.

9. Which among the following violates the principle of encapsulation almost always?

a) Local variables

b) Global variables

c) Public variables

d) Array variables

View Answer

Answer: b

Explanation: Global variables almost always violates the principles of encapsulation. Encapsulation says
the data should be accessed only by required set of elements. But global variable is accessible
everywhere, also it is most prone to changes. It doesn’t hide the internal working of program.

10. Which among the following would destroy the encapsulation mechanism if it was allowed in
programming?

a) Using access declaration for private members of base class

b) Using access declaration for public members of base class

c) Using access declaration for local variable of main() function

d) Using access declaration for global variables

View Answer

Answer: a

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Explanation: If using access declaration for private members of base class was allowed in programming,
it would have destroyed whole concept of encapsulation. As if it was possible, any class which gets
inherited privately, would have been able to inherit the private members of base class, and hence could
access each and every member of base class.

11. Which among the following can be a concept against encapsulation rules?

a) Using function pointers

b) Using char* string pointer to be passed to non-member function

c) Using object array

d) Using any kind of pointer/array address in passing to another function

View Answer

Answer: d

Explanation: If we use any kind of array or pointer as data member which should not be changed, but in
some case its address is passed to some other function or similar variable. There are chances to modify its
whole data easily. Hence Against encapsulation.

12. Consider the following code and select the correct option:

advertisement

class student

int marks;

public : int* fun()

return &marks;

};

main()

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
{

student s;

int *ptr=c.fun();

return 0;

a) This code is good to go

b) This code may result in undesirable conditions

c) This code will generate error

d) This code violates encapsulation

View Answer

Answer: d

Explanation: This code violates the encapsulation. By this code we can get the address of the private
member of the class, hence we can change the value of private member, which is against the rules.

13. Consider the code and select the wrong choice:

class hero

char name[10];

public : void disp()

cout<<name;

};

a) This maintains encapsulation

b) This code doesn’t maintain encapsulation

c) This code is vulnerable


For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
d) This code gives error

View Answer

Answer: a

Explanation: This code maintains encapsulation. Here the private member is kept private. Outside code
can’t access the private members of class. Only objects of this class will be able to access the public
member function at maximum.

14. Encapsulation is the way to add functions in a user defined structure.

a) True

b) False

View Answer

Answer: b

Explanation: False, because we can’t call these structures if member functions are involved, it must be
called class. Also, it is not just about adding functions, it’s about binding data and functions together.

15. Using encapsulation data security is ___________

a) Not ensured

b) Ensured to some extent

c) Purely ensured

d) Very low

View Answer

Answer: b

Explanation: The encapsulation can only ensure the data security to some extent. If pointer and addresses
are misused, it may violate encapsulation. Use of global variables also makes the program vulnerable,
hence we can’t say that encapsulation gives pure security.

7. Questions and Answers – Abstraction

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Abstraction”.

1. Which among the following best defines abstraction?

a) Hiding the implementation

b) Showing the important data

c) Hiding the important data

d) Hiding the implementation and showing only the features

View Answer

Answer: d

Explanation: It includes hiding the implementation part and showing only the required data and features
to the user. It is done to hide the implementation complexity and details from the user. And to provide a
good interface in programming.

2. Hiding the implementation complexity can:

a) Make the programming easy

b) Make the programming complex

c) Provide more number of features

d) Provide better features

View Answer

Answer: a

Explanation: It can make the programming easy. The programming need not know how the inbuilt
functions are working but can use those complex functions directly in the program. It doesn’t provide
more number of features or better features.

3. Class is _________ abstraction

a) Object

b) Logical

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
c) Real

d) Hypothetical

View Answer

Answer: b

Explanation: Class is logical abstraction because it provides a logical structure for all of its objects. It
gives an overview of the features of an object.

4. Object is ________ abstraction

a) Object

b) Logical

c) Real

d) Hypothetical

View Answer

Answer: c

Explanation: Object is real abstraction because it actually contains those features of class. It is the
implementation of overview given by class. Hence the class is logical abstraction and its object is real.

5. Abstraction gives higher degree of ________

a) Class usage

b) Program complexity

c) Idealized interface

d) Unstable interface

View Answer

Answer: c

Explanation: It is to idealize the interface. In this way the programmer can use the programming features
more efficiently and can code better. It can’t increase the program complexity, as the feature itself is
made to hide it.
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
6. Abstraction can apply to:

a) Control and data

b) Only data

c) Only control

d) Classes

View Answer

Answer: a

Explanation: Abstraction applies to both. Control abstraction involves use of subroutines and control flow
abstraction. Data abstraction involves handling pieces of data in meaningful ways.

7. Which among the following can be viewed as combination of abstraction of data and code.

a) Class

b) Object

c) Inheritance

d) Interfaces

View Answer

Answer: b

Explanation: Object can be viewed as abstraction of data and code. It uses data members and their
functioning as data abstraction. Code abstraction as use of object of inbuilt class.

8. Abstraction principle includes___________

a) Use abstraction at its minimum

b) Use abstraction to avoid longer codes

c) Use abstraction whenever possible to avoid duplication

d) Use abstraction whenever possible to achieve OOP

View Answer

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Answer: c

Explanation: Abstraction principle includes use of abstraction to avoid duplication (usually of code). It
this way the program doesn’t contain any redundant functions and make the program efficient.

9. Higher the level of abstraction, higher are the details.

a) True

b) False

View Answer

Answer: b

Explanation: Higher the level of abstraction, lower are the details. The best way to understand this is to
consider a whole system that is highest level of abstraction as it hides everything inside. And next lower
level would contain few of the computer components and so on.

10. Encapsulation and abstraction differ as:

a) Binding and Hiding respectively

b) Hiding and Binding respectively

c) Can be used any way

d) Hiding and hiding respectively

View Answer

Answer: a

Explanation: Abstraction is hiding the complex code. For example we directly use cout object in C++ but
we don’t know how is it actually implemented. Encapsulation is data binding, as in, we try to combine the
similar type of data and functions together.

11. In terms of stream and files________

a) Abstraction is called a stream and device is called a file

b) Abstraction is called a file and device is called a stream

c) Abstraction can be called both file and stream

d) Abstraction can’t be defined in terms of files and stream

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
View Answer

Answer: a

Explanation: Abstraction is called stream to provide a level of complexity hiding, for how the files
operations are actually done. Actual devices are called file because in one way or another, those can be
considered as single entity and there is nothing hidden.

12. If two classes combine some private data members and provides public member functions to
access and manipulate those data members. Where is abstraction used?

a) Using private access specifier for data members

b) Using class concept with both data members and member functions

c) Using public member functions to access and manipulate the data members

d) Data is not sufficient to decide what is being used

View Answer

Answer: c

Explanation: It is the concept of hiding program complexity and actual working in background. Hence use
of public member functions illustrates abstraction here.

advertisement

13. A phone is made up of many components like motherboard, camera, sensors and etc. If the
processor represents all the functioning of phone, display shows the display only, and the phone is
represented as a whole. Which among the following have highest level of abstraction?

a) Motherboard

b) Display

c) Camera

d) Phone

View Answer

Answer: d
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Explanation: Phone as a whole have the highest level of abstraction. This is because the phone being a
single unit represents the whole system. Whereas motherboard, display and camera are its components.

14. Which among the following is not a level of abstraction:

a) Logical level

b) Physical level

c) View level

d) External level

View Answer

Answer: d

Explanation: Abstraction is generally divided into 3 different levels, namely, logical, physical and view
level. External level is not defined in terms of abstraction.

15. Using higher degree of abstraction __________

a) May get unsafe

b) May reduce readability

c) Can be safer

d) Can increase vulnerability

View Answer

Answer: c

Explanation: It will make the code safer. One may think it reduces the readability, but the fact is, it
actually helps us understand the code better. We don’t have to read the complex code which is of no use
in understanding the program.

8. Questions and Answers – Constructors


This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs)
focuses on “Constructors”.

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
1. Which among the following is called first, automatically, whenever an object is created?

a) Class

b) Constructor

c) New

d) Trigger

View Answer

Answer: b

Explanation: Constructors are the member functions which are called automatically whenever an object is
created. It is a mandatory functions to be called for an object to be created as this helps in initializing the
object to a legal initial value for the class.

2. 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

View Answer

Answer: c

Explanation: Constructors are predefined implicitly, even if the programmer doesn’t define any of them.
Even if the programmer declares a constructor, it’s not necessary that it must contain some definition.

3. Which among the following is correct?

a) class student{ public: int student(){} };

b) class student{ public: void student (){} };

c) class student{ public: student{}{} };

d) class student{ public: student(){} };

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
View Answer

Answer: d

Explanation: The constructors must not have any return type. Also, the body may or may not contain any
body. Defining default constructor is optional, if you are not using any other constructor.

4. In which access should a constructor be defined, so that object of the class can be created in any
function?

a) Public

b) Protected

c) Private

d) Any access specifier will work

View Answer

Answer: a

Explanation: Constructor function should be available to all the parts of program where the object is to be
created. Hence it is advised to define it in public access, so that any other function is able to create
objects.

5. How many types of constructors are available for use in general (with respect to parameters)?

a) 2

b) 3

c) 4

d) 5

View Answer

Answer: a

Explanation: Two types of constructors are defined generally, namely, default constructor and
parameterized constructor. Default constructor is not necessary to be defined always.

6. If a programmer defines a class and defines a default value parameterized constructor inside it.

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
He has not defined any default constructor. And then he try to create the object without passing
arguments, which among the following will be correct?

a) It will not create the object (as parameterized constructor is used)

b) It will create the object (as the default arguments are passed )

c) It will not create the object ( as the default constructor is not defined )

d) It will create the object ( as at least some constructor is defined )

View Answer

Answer: b

Explanation: It will create the object without any problem, because the default arguments use the default
value if no value is passed. Hence it is equal to default constructor with zero parameters. But it will not
create the object if signature doesn’t match.

7. Default constructor must be defined, if parameterized constructor is defined and the object is to
be created without arguments.

a) True

b) False

View Answer

Answer: a

Explanation: If the object is create without arguments and only parameterized constructors are used,
compiler will give an error as there is no default constructor defined. And some constructor must be
called so as to create an object in memory.

8. If class C inherits class B. And B has inherited class A. Then while creating the object of class C,
what will be the sequence of constructors getting called?

a) Constructor of C then B, finally of A

b) Constructor of A then C, finally of B

c) Constructor of C then A, finally B

d) Constructor of A then B, finally C

View Answer

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Answer: d

Explanation: While creating the object of class C, its constructor would be called by default. But, if the
class is inheriting some other class, firstly the parent class constructor will be called so that all the data is
initialized that is being inherited.

9. In multiple inheritance, if class C inherits two classes A and B as follows, which class constructor
will be called first:

class A{ };

class B{ };

class C: public A, public B{ };

a) A()

b) B()

c) C()

d) Can’t be determined

View Answer

Answer: a

Explanation: Constructor of class A will be called first. This is because the constructors in multiple
inheritance are called in the sequence in which they are written to be inherited. Here A is written first,
hence it is called first.

10. Which among the following is true for copy constructor?

a) The argument object is passed by reference

b) It can be defined with zero arguments

c) Used when an object is passed by value to a function

d) Used when a function returns an object

View Answer

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Answer: b

Explanation: It can’t be defined with zero number of arguments. This is because to copy one object to
another, the object must be mentioned so that compiler can take values from that object.

advertisement

11. If the object is passed by value to a copy constructor:

a) Only public members will be accessible to be copied

b) That will work normally

c) Compiler will give out of memory error

d) Data stored in data members won’t be accessible

View Answer

Answer: c

Explanation: Compiler runs out of memory. This is because while passing the argument by value, a
constructor of the object will be called. That in turn called another object constructor for values, and this
goes on. This is like a constructor call to itself, and this goes on infinite times, hence it must be passed by
reference, so that the constructor is not called.

12. Which object will be created first?

class student

int marks;

};

student s1, s2, s3;

a) s1 then s2 then s3

b) s3 then s2 then s1

c) s2 then s3 then s1

d) All are created at same time


For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
View Answer

Answer: a

Explanation: The objects are created in the sequence of how they are written. This happens because the
constructors are called in the sequence of how the objects are mentioned. This is done in sequence.

13. Which among the following helps to create a temporary instance?

a) Implicit call to a default constructor

b) Explicit call to a copy constructor

c) Implicit call to a parameterized constructor

d) Explicit call to a constructor

View Answer

Answer: d

Explanation: Explicit call to a constructor can let you create temporary instance. This is because the
temporary instances doesn’t have any name. Those are deleted from memory as soon as their reference is
removed.

14. Which among the following is correct for the class defined below?

class student

int marks;

public: student(){}

student(int x)

marks=x;

};

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
main()

student s1(100);

student s2();

student s3=100;

return 0;

a) Object s3, syntax error

b) Only object s1 and s2 will be created

c) Program runs and all objects are created

d) Program will give compile time error

View Answer

Answer: c

Explanation: It is a special case of constructor with only 1 argument. While calling a constructor with one
argument, you are actually implicitly creating a conversion from the argument type to the type of class.
Hence you can directly specify the value of that one argument with assignment operator.

15. 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

View Answer

Answer: a

Explanation: Each constructor must differ in the number of arguments it accepts and the type of
arguments. This actually defines the constructor signature. This helps to remove the ambiguity and define
a unique constructor as required.

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
9. Questions and Answers – Types of Constructors
This set of Object Oriented Programming online quiz focuses on “Types of Constructors”.

1. How many types of constructors are available, in general, in any language?

a) 2

b) 3

c) 4

d) 5

View Answer

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-


computer-science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php

Answer: b

Explanation: There are 3 types of constructors in general, namely, default constructors, parameterized
constructors and copy constructors. Default one is called whenever an object is created without
arguments.

2. Choose the correct option for the following code.

class student

int marks;

student s1;

student s2=2;

a) Object s1 should be passed with argument.

b) Object s2 should not be declared

c) Object s2 will not be created, but program runs


For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
d) Program gives compile time error

View Answer

Answer: d

Explanation: The object s2 can be assigned with one value only if a single argument constructor is
defined in class, but here, it can’t be done as no constructor is defined. Hence every object must be
declare or created without using arguments.

3. Which constructor is called while assigning some object with another?

a) Default

b) Parameterized

c) Copy

d) Direct assignment is used

View Answer

Answer: c

Explanation: Copy constructor is used while an object is assigned with another. This is mandatory since
we can’t decide which member should be assigned to which member value. By using copy constructor,
we can assign the values in required form.

4. It’s necessary to pass object by reference in copy constructor because:

a) Constructor is not called in pass by reference

b) Constructor is called in pass by reference only

c) It passes the address of new constructor to be created

d) It passes the address of new object to be created

View Answer

Answer: a

Explanation: Object must be passed by reference to copy constructor because constructor is not called in
pass by reference. Otherwise, in pass by value, a temporary object will be created which in turn will try to

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
call its constructor that is already being used. This results in creating infinite number of objects and hence
memory shortage error will be shown.

5. Which specifier applies only to the constructors?

a) Public

b) Protected

c) Implicit

d) Explicit

View Answer

Answer: d

Explanation: The keyword explicit can be used while defining the constructor only. This is used to
suppress the implicit call to the constructor. It ensures that the constructors are being called with the
default syntax only (i.e. only by using object and constructor name).

6. Which among the following is true?

a) Default constructor can’t be defined by the programmer

b) Default parameters constructor isn’t equivalent to default constructor

c) Default constructor can be called explicitly

d) Default constructor is and always called implicitly only

View Answer

Answer: c

Explanation: Default constructors can be called explicitly anytime. They are specifically used to allocate
memory space for the object in memory, in general. It is not necessary that these should always be called
implicitly.

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

a) Default

b) Parameterized

c) Copy

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
d) Constructors don’t have a return type

View Answer

Answer: d

Explanation: Constructors don’t return any value. Those are special functions, whose return type is not
defined, not even void. This is so because the constructors are meant to initialize the members of class
and not to perform some task which can return some value to newly created object.

8. Why do we use static constructors?

a) To initialize the static members of class

b) To initialize all the members with static value

c) To delete the static members when not required

d) To clear all the static members initialized values

View Answer

Answer: a

Explanation: Static constructors help in initializing the static members of the class. This is provided
because the static members are not considered to be property of the object, rather they are considered as
the property of class.

9. When and how many times a static constructor is called?

a) Created at time of object destruction

b) Called at first time when an object is created and only one time

c) Called at first time when an object is created and called with every new object creation

d) Called whenever an object go out of scope

View Answer

Answer: b

Explanation: Those are called at very first call of object creation. That is called only one time because the
value of static members must be retained and continued from the time it gets created.

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
10. Which among the following is true for static constructor?

a) Static constructors are called with every new object

b) Static constructors are used initialize data members to zero always

c) Static constructors can’t be parameterized constructors

d) Static constructors can be used to initialize the non-static members also

View Answer

Answer: c

Explanation: Static constructors can’t be parameterized constructors. Those are used to initialize the value
of static members only. And that must be a definite value. Accepting arguments may make it possible that
static members loses their value with every new object being created.

advertisement

11. Within a class, only one static constructor can be created.

a) True

b) False

View Answer

Answer: a

Explanation: Since the static constructors are can’t be parameterized, they can’t be overloaded. Having
this case, only one constructor will be possible to be created in a local scope, because the signature will
always be same and hence it will not be possible to overload static constructor.

12. Default constructor initializes all data members as:

a) All numeric member with some garbage values and string to random string

b) All numeric member with some garbage values and string to null

c) All numeric member with zero and strings to random value

d) All numeric member with zero and strings to null

View Answer
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Answer: d

Explanation: Default constructor, which even the programmer doesn’t define, always initialize the values
as zero if numeric and null if string. This is done so as to avoid the accidental values to change the
conditional statements being used and similar conditions.

13. When is the static constructor called?

a) After the first instance is created

b) Before default constructor call of first instance

c) Before first instance is created

d) At time of creation of first instance

View Answer

Answer: c

Explanation: The static constructor is called before creation of first instance of that class. This is done so
that even the first instance can use the static value of the static members of the class and manipulate as
required.

14. If constructors of a class are defined in private access, then:

a) The class can’t be inherited

b) The class can be inherited

c) Instance can be created only in another class

d) Instance can be created anywhere in the program

View Answer

Answer: a

Explanation: If the constructors are defined in private access, then the class can’t be inherited by other
classes. This is useful when the class contains static members only. The instances can never be created.

15. Which among the following is correct, based on the given code below:

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
class student

int marks;

public : student()

cout<<”New student details can be added now”;

};

student s1;

a) Cout can’t be used inside the constructor

b) Constructor must contain only initializations

c) This program works fine

d) This program produces errors

View Answer

Answer: c

Explanation: This program will work fine. This is because it is not mandatory that a constructor must
contain only initialization only. If you want to perform a task on each instance being created, that code
can be written inside the constructor.

10. Questions and Answers – Copy Constructor


This set of Basic Object Oriented Programming Questions and Answers focuses on “Copy Constructor”.

1. Copy constructor is a constructor which ________________

a) Creates an object by copying values from any other object of same class

b) Creates an object by copying values from first object created for that class

c) Creates an object by copying values from another object of another class

d) Creates an object by initializing it with another previously created object of same class
For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
View Answer

Answer: d

Explanation: The object that has to be copied to new object must be previously created. The new object
gets initialized with the same values as that of the object mentioned for being copied. The exact copy is
made with values.

2. The copy constructor can be used to:

a) Initialize one object from another object of same type

b) Initialize one object from another object of different type

c) Initialize more than one object from another object of same type at a time

d) Initialize all the objects of a class to another object of another class

View Answer

Answer: a

Explanation: The copy constructor has the most basic function to initialize the members of an object with
same values as that of some previously created object. The object must be of same class.

3. If two classes have exactly same data members and member function and only they differ by class
name. Can copy constructor be used to initialize one class object with another class object?

a) Yes, possible

b) Yes, because the members are same

c) No, not possible

d) No, but possible if constructor is also same

View Answer

Answer: c

Explanation: The restriction for copy constructor is that it must be used with the object of same class.
Even if the classes are exactly same the constructor won’t be able to access all the members of another
class. Hence we can’t use object of another class for initialization.

4. The copy constructors can be used to ________


For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
a) Copy an object so that it can be passed to a class

b) Copy an object so that it can be passed to a function

c) Copy an object so that it can be passed to another primitive type variable

d) Copy an object for type casting

View Answer

Answer: b

Explanation: When an object is passed to a function, actually its copy is made in the function. To copy the
values, copy constructor is used. Hence the object being passed and object being used in function are
different.

5. Which returning an object, we can use ____________

a) Default constructor

b) Zero argument constructor

c) Parameterized constructor

d) Copy constructor

View Answer

Answer: d

Explanation: While returning an object we can use the copy constructor. When we assign the return value
to another object of same class then this copy constructor will be used. And all the members will be
assigned the same values as that of the object being returned.

6. If programmer doesn’t define any copy constructor then _____________

a) Compiler provides an implicit copy constructor

b) Compiler gives an error

c) The objects can’t be assigned with another objects

d) The program gives run time error if copying is used

View Answer

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
Answer: a

Explanation: The compiler provides an implicit copy constructor. It is not mandatory to always create an
explicit copy constructor. The values are copied using implicit constructor only.

7. If a class implements some dynamic memory allocations and pointers then _____________

a) Copy constructor must be defined

b) Copy constructor must not be defined

c) Copy constructor can’t be defined

d) Copy constructor will not be used

View Answer

Answer: a

Explanation: In the case where dynamic memory allocation is used, the copy constructor definition must
be given. The implicit copy constructor is not capable of manipulating the dynamic memory and pointers.
Explicit definition allows to manipulate the data as required.

8. What is the syntax of copy constructor?

a) classname (classname &obj){ /*constructor definition*/ }

b) classname (cont classname obj){ /*constructor definition*/ }

c) classname (cont classname &obj){ /*constructor definition*/ }

d) classname (cont &obj){ /*constructor definition*/ }

View Answer

Answer: c

Explanation: The syntax must contain the class name first, followed by the classname as type and &object
within parenthesis. Then comes the constructor body. The definition can be given as per requirements.

9. Object being passed to a copy constructor ___________

a) Must be passed by reference

b) Must be passed by value

c) Must be passed with integer type


For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-
science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
d) Must not be mentioned in parameter list

View Answer

Answer: a

Explanation: This is mandatory to pass the object by reference. Otherwise the object will try to create
another object to copy its values, in turn a constructor will be called, and this will keep on calling itself.
This will cause the compiler to give out of memory error.

10. Out of memory error is given when the object _____________ to the copy constructor.

a) Is passed with & symbol

b) Is passed by reference

c) Is passed as

d) Is not passed by reference

View Answer

Answer: d

Explanation: All the options given, directly or indirectly indicate that the object is being passed by
reference. And if object is not passed by reference then the out of memory error is produced. Due to
infinite constructor call of itself.

11. Copy constructor will be called whenever the compiler __________

a) Generates implicit code

b) Generates member function calls

c) Generates temporary object

d) Generates object operations

View Answer

Answer: c

Explanation: Whenever the compiler creates a temporary object, copy constructor is used to copy the
values from existing object to the temporary object.

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
12. The deep copy is possible only with the help of __________

a) Implicit copy constructor

b) User defined copy constructor

c) Parameterized constructor

d) Default constructor

View Answer

Answer: b

Explanation: While using explicit copy constructor, the pointers of copied object point to the intended
memory location. This is assured since the programmers themselves manipulate the addresses.

advertisement

13. Can a copy constructor be made private?

a) Yes, always

b) Yes, if no other constructor is defined

c) No, never

d) No, private members can’t be accessed

View Answer

Answer: a

Explanation: The copy constructor can be defined private. If we make it private then the objects of the
class can’t be copied. It can be used when a class used dynamic memory allocation.

14. The arguments to a copy constructor _____________

a) Must be const

b) Must not be cosnt

c) Must be integer type

d) Must be static

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php
View Answer

Answer: a

Explanation: The object should not be modified in the copy constructor. Because the object itself is being
copied. When the object is returned from a function, the object must be a constant otherwise the compiler
creates a temporary object which can die anytime.

15. Copy constructors are overloaded constructors.

a) True

b) False

View Answer

Answer: a

Explanation: The copy constructors are always overloaded constructors. They has to be. All the classes
have a default constructor and other constructors are basically overloaded constructors.

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-


computer-science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php

For Computer Lecturer Test Pdf Download https://www.doc4shares.com/ppsc-lecturer-of-computer-


science-solved-past-papers-mcqs-and-test-preparation-data-in-pdf.php

You might also like