0% found this document useful (0 votes)
160 views

JECA Mock2 (Object Oriented Programming) - 2023-06-13

The document is a mock exam for an object oriented programming course. It contains 9 multiple choice questions testing concepts like encapsulation, copy constructors, destructors, and class sizes. The questions cover topics like when objects are passed by reference, the difference between classes and structures, when temporary objects are created, and access specifiers for constructors and protected members.

Uploaded by

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

JECA Mock2 (Object Oriented Programming) - 2023-06-13

The document is a mock exam for an object oriented programming course. It contains 9 multiple choice questions testing concepts like encapsulation, copy constructors, destructors, and class sizes. The questions cover topics like when objects are passed by reference, the difference between classes and structures, when temporary objects are created, and access specifiers for constructors and protected members.

Uploaded by

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

My Profile Home Log Out

Welcome Partha Garai (impersonating Poulami


Baidya)
JECA Mock2 (Object Oriented Programming)_2023-06-13

Logged in as Student
Saturday 17th Jun, 2023 05:04:08 PM

Search Student
JECA Joint Entrance Exam MCA (WB
Section : J-1st_Sem 2022 Course :
Academics and Personal Info JECA)

Year : 2022-2023 Full Marks : 30


View Attendance

View Marks
Group A (Object Oriented Programming): Answer All question(s)
Submit Assignments 1. Object being passed to a copy constructor ___________ Marks: 1 (Correct: a)

Knowledge Assessment a) Must be passed by b) Must be passed by c) Must be passed with d) Must not be mentioned
reference value integer type in parameter list
View Books
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.
View Timetable
2. Which among the following best describes encapsulation? Marks: 1 (Correct: d)
Download Class Materials c) It is a way of combining d) It is a way of combining
a) It is a way of combining b) It is a way of various data members and various data members
View Previous Questions various data members into a combining various member member functions into a and member functions
single unit functions into a single unit single unit which can operate that operate on those data
on any data members into a single unit
Submit Course Feedbacks
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.

3. What is the additional feature in classes that was not in structures? Marks: 1 (Correct: b)
a) Data members b) Member functions c) Static data allowed d) Public access specifier

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.

4. Which among the following is true for copy constructor? Marks: 1 (Correct: b)
a) The argument object is b) It can be defined with zero c) Used when an object is d) Used when a function
passed by reference arguments passed by value to a function returns an object

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.

5. When an object is returned___________ Marks: 1 (Correct: a)


d) Object are returned
b) The same object used in c) The Object can be
a) A temporary object is implicitly, we can’t say
function is used to return the returned without creation of
created to return the value how it happens inside
value temporary object
program

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

6. Which specifier allows a programmer to make the private members which can be Marks: 1 (Correct: c)
inherited?
a) Private b) Default c) Protected d) Protected and default

Explanation: Protected access is used to make the members private. But those members can be inherited. This gives both security and
code reuse capability to a program.

7. In which access should a constructor be defined, so that object of the class can be Marks: 1 (Correct: a)
created in any function?
d) Any access specifier
a) Public b) Protected c) Private
will work

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.

8. When is the destructor of a global object called? Marks: 1 (Correct: a)

d) Anytime when
a) Just before end of program b) Just after end of program c) With the end of program
object is not needed

Explanation: This is because the lifespan of global object is from start of the program, till the end of the program. And hence program
end is the end of global object too. Just before the end of program, the destructor will be called to free the acquired resources by the
objects.

9. What is size of the object of following class (64 bit system)? Marks: 1 (Correct: c)

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

a) 20 b) 22 c) 24 d) 28

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.

This Site Maintained by Webtech Services


10. The arguments to a copy constructor _____________ Marks: 1 (Correct: a)
a) Must be const b) Must not be cosnt c) Must be integer type d) Must be static

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.

11. Which feature in OOP is used to allocate additional function to a predefined Marks: 1 (Correct: a)
operator in any language?
a) Operator Overloading b) Function Overloading c) Operator Overriding d) Function Overriding

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

12. When is the constructor called for an object? Marks: 1 (Correct: d)

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


required derived created is created

Explanation: The constructor is called as soon as the object is created. The overloading comes into picture as to identify which
constructor have to be called depending on arguments passed in the creation of object.

13. Object declared in main() function _____________ Marks: 1 (Correct: c)


a) Can be used by any other b) Can be used by main() c) Can’t be used by any other d) Can be accessed using
function function of any other program function scope resolution operator

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.

14. Which specifier applies only to the constructors? Marks: 1 (Correct: d)

a) Public b) Protected c) Implicit d) Explicit

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

15. Which feature of OOP is indicated by the following code? Marks: 1 (Correct: d)

class student{ int marks; };

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

c) Inheritance and d) Encapsulation and


a) Inheritance b) Polymorphism
polymorphism Inheritance

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 the topper class but that doesn’t mean that default
constructor is overloaded.

16. Which returning an object, we can use ____________ Marks: 1 (Correct: d)

a) Default constructor b) Zero argument constructor c) Parameterized constructor d) Copy constructor

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.

17. Which among the following is true? Marks: 1 (Correct: a)


a) First the constructor of b) First the constructor of
c) First constructor called is d) Constructors are called
parent classes are called in child classes are called in the
of the object being created randomly
sequence of inheritance sequence of inheritance

Explanation: First the constructor of parent class are called. The order in which the parent class constructors are called is same in the
sequence of inheritance used.

18. Which of the following pairs are similar? Marks: 1 (Correct: b)

a) Class and object b) Class and structure c) Structure and object d) Structure and functions

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.

19. Class is pass by _______ Marks: 1 (Correct: b)


c) Value or Reference,
a) Value b) Reference d) Copy
depending on program

Explanation: Classes are pass by reference, and the structures are pass by copy. It doesn’t depend on the program.

20. Which Feature of OOP illustrated the code reusability? Marks: 1 (Correct: d)
a) Polymorphism b) Abstraction c) Encapsulation d) Inheritance

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.

21. If programmer doesn’t define any copy constructor then _____________ Marks: 1 (Correct: a)
d) The program gives run
a) Compiler provides an c) The objects can’t be
b) Compiler gives an error time error if copying is
implicit copy constructor assigned with another objects used

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.

22. A phone is made up of many components like motherboard, camera, sensors and Marks: 1 (Correct: d)
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?

This Site Maintained by Webtech Services


a) Motherboard b) Display c) Camera d) Phone

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.

23. Which class can have member functions without their implementation? Marks: 1 (Correct: d)

a) Default class b) String class c) Template class d) Abstract class

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

24. Which of the following is incorrect? Marks: 1 (Correct: c)


d) class student{ }; student
a) class student{ }s; b) class student{ }; student s; c) class student{ }s[];
s[5];

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.

25. When OOP concept did first came into picture? Marks: 1 (Correct: a)

a) 1970’s b) 1980’s c) 1993 d) 1995

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.

26. Size of a class is _____________ Marks: 1 (Correct: d)


a) Sum of the size of all the b) Sum of the size of all the
c) Size of the largest size of d) Classes doesn’t
variables declared inside the variables along with inherited
variable have any size
class variables in the class

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.

27. What is output of the following program? Marks: 1 (Correct: a)

class student

public : int marks;

void disp()

cout<<”its base class”

};

class topper:public student

public :

void disp()

cout<<”Its derived class”;

void main() { student s; topper t;

s.disp();

t.disp();

a) Its base classIts derived b) Its base class Its derived c) Its derived classIts base d) Its derived class Its
class class class base class

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.

28. Which class/set of classes can illustrate polymorphism in the following code? Marks: 1 (Correct: c)

abstract class student

public : int marks;

calc_grade();

class topper:public student

This Site Maintained by Webtech Services


{

public : calc_grade()

return 10;

};

class average:public student

public : calc_grade()

return 20;

};

class failed{ int marks; };

d) Class failed should also


b) Only class student and c) All class student, topper
a) Only class student can inherit class student for
topper together can show and average together can
show polymorphism this code to work for
polymorphism show polymorphism
polymorphism

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.

29. What happens when an object is passed by reference? Marks: 1 (Correct: a)

b) Destructor is called at c) Destructor is called when d) Destructor is called


a) Destructor is not called
end of function function is out of scope when called explicitly

Explanation: The destructor is never called in this situation. The concept is that when an object is passed by reference to the function,
the constructor is not called, but only the main object will be used. Hence no destructor will be called at end of function.

30. Which among the following is false? Marks: 1 (Correct: a)


d) Constructors
a) Constructor can’t be b) Constructors can’t be c) Constructors can be
overloading depends on
overloaded in Kotlin called recursively in java overloaded in C++
different signatures

Explanation: Kotlin language allows constructor overloading. This is a basic feature for the constructors. The constructor overloading
allows the object to be initialized according to the user.

Back

This Site Maintained by Webtech Services

You might also like