Object Oriented Programming Computer Science MCQs.

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

a. Java

b. C++

c. SmallTalk

d. Kotlin

Answer: (c). SmallTalk

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

Answer: (b). Instance of an object

3. Who invented OOP?

a. Alan Kay

b. Andrea Ferro

c. Dennis Ritchie

d. Adele Goldberg

Answer: (a). Alan Kay

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

Answer: (b). Member functions

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

a. Code reusability

b. Modularity

c. Duplicate/Redundant data

d. Efficient Code

Answer: (c). Duplicate/Redundant data

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

a. True

b. False

c. May be

d. , “Can’t say”

Answer: (b). False

7. Which Feature of OOP illustrated the code reusability?

a. Polymorphism

b. Abstraction

c. Encapsulation

d. Inheritance

Answer: (d). Inheritance

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

a. C++

b. Java

c. Kotlin

d. Small Talk

Answer: (b). 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

Answer: (d). As many as you want

10. When OOP concept did first came into picture?

a. 1970s

b. 1980s

c. 1993

d. 1995

Answer: (a). 1970s

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

Answer: (a). It supports usual declaration of primitive data types

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

Answer: (b). Code must contain at least one class

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

Answer: (d). OOP can be used without using any header file

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

Answer: (c). Encapsulation and Abstraction

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

Answer: (a). Use of this pointer

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

a. Abstract Class

b. Final Class

c. Start Class

d. String Class

Answer: (c). Start Class

17. Class is pass by _______

a. Value

b. Reference

c. Value or Reference, depending on program

d. Copy

Answer: (b). Reference

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

Answer: (a). Private

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

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

20. Which is known as generic class?

a. Abstract class

b. Final class

c. Template class

d. Efficient Code

Answer: (c). Template class

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

Answer: (d). Classes doesn’t have any size

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

a. Default class

b. String class

c. Template class

d. Abstract class

Answer: (d). Abstract class

23. 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 its methods

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

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

Answer: (d). Depends on access specifier and inheritance used

25. State True or False. Class with main() function can be inherited.

a. True

b. False

c. May be

d. , “Can’t say”

Answer: (a). True

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

Answer: (c). Member functions need not be declared inside the class definition

27. Which syntax for class definition is wrong?

a. class student{ student(int a){} };

b. student class{ };

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

d. class student{ student(int a){} };

Answer: (b). student class{ };

28. Which of the following pairs are similar?

a. Class and object

b. Class and structure

c. Structure and object

d. Structure and functions

Answer: (b). Class and structure

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

Answer: (b). Class definition must be ended with a colon

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

a. Anonymous class

b. Nested class

c. Parent class

d. Abstract class

Answer: (d). Abstract class

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

Answer: (a). Instance of a class

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

Answer: (d). As many as you want

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

Answer: (c). Objects can’t be passed by reference

34. Which of the following is incorrect?

a. class student{ }s;

b. class student{ };  student s;

c. class student{ }s;

d. class student{ }; student s5;

Answer: (c). class student{ }s;

35. The object can’t be:

a. Passed by reference

b. Passed by value

c. Passed by copy

d. Passed as function

Answer: (d). Passed as function

36. What is size of the object of following class (64 bit system)?class student { int rollno; char name20; static int studentno; };

a. 20

b. 22

c. 24

d. 28

Answer: (c). 24

37. Functions can’t return objects. State True or False.

a. True

b. False

c. May be

d. , “Can’t say”

Answer: (b). False

38. How members of an object are accessed?

a. Using dot operator/period symbol

b. Using scope resolution operator

c. Using member names directly

d. Using pointer only

Answer: (a). Using dot operator/period symbol

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

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

40. Which among the following is wrong?

a. class student{ }; student s;

b. abstract class student{ }; student s;

c. abstract class student{ }s50000000;

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

Answer: (b). abstract class student{ }; student s;

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

Answer: (c). Can’t be used by any other function

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

Answer: (a). A temporary object is created to return the value

43. Which among the following is correct?

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

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

Answer: (c). class student{ }s1,s2; s1=s2;

44. 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 s3={ s(394, 9); s(394, 9); s(394,9); };

b. student s2={  s(394,9), s(222,5) };

c. student s2={  s1(392,9), s2(222,5)  };

d. student s2={  s392,9,  s2222,5  };

Answer: (b). student s2={  s(394,9), s(222,5) };

45. 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. State True or False.

a. True

b. False

c. May be

d. , “Can’t say”

Answer: (b). False

46. Which feature of OOP indicates code reusability?

a. Encapsulation

b. Inheritance

c. Abstraction

d. Polymorphism

Answer: (b). Inheritance

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

a. Encapsulation

b. Inheritance

c. Polymorphism

d. Abstraction

Answer: (c). Polymorphism

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

Answer: (d). Encapsulation

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

Answer: (c). Data may/may not be declared using object

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

a. Platform independent

b. Data binding

c. Message passing

d. Data hiding

Answer: (a). Platform independent

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

Answer: (d). Encapsulation and Inheritance

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

Answer: (d). Basically all the features of OOP gets violated

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

a. 7

b. 6

c. 5

d. 4

Answer: (a). 7

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

a. Data transfer

b. Data Binding

c. Message Passing

d. Message reading

Answer: (c). Message Passing

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

a. Nested class

b. Enclosing class

c. Inline function

d. Virtual Function

Answer: (d). Virtual Function

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

Answer: (a). Operator Overloading

57. Which among doesn’t illustrates polymorphism?

a. Function overloading

b. Function overriding

c. Operator overloading

d. Virtual function

Answer: (b). Function overriding

58. Exception handling is feature of OOP. State True or False.

a. True

b. False

c. May be

d. , “Can’t say”

Answer: (a). True

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

Answer: (d). The language must follow all the rules of OOP

60. 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. Its vice-versa is true

Answer: (a). Always true for any programming language

61. \tWhich 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

Answer: (a). It is the ability for a message/data to be processed in more than one form

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

Answer: (c). Object-based language

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

a. SmallTalk

b. Java

c. C++

d. Ada

Answer: (d). Ada

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

Answer: (c). Polymorphism

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

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

Answer: (c). All class student, topper and average together can show polymorphism

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

a. Inline function

b. Virtual function

c. Undefined functions

d. Class member functions

Answer: (b). Virtual function

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

Answer: (b). Function with highest priority in compiler

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

Answer: (a). Static member functions

69. What is output of the following program?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 class

b. Its base class Its derived class

c. Its derived classIts base class

d. Its derived class Its base class

Answer: (a). Its base classIts derived class

70. Which among the following can show polymorphism?

a. Overloading ||

b. Overloading +=

c. Overloading <<

d. Overloading &&

Answer: (c). Overloading <<

71. Find the output of the program:class education{ char name10; public : disp() {  cout<<”Its education system”; } class school:public education { public: void dsip() {  cout<<”Its school education system”; }  }; void main() {        school s;        s. disp(); }}

a. Its school education system

b. Its education system

c. Its school education systemIts education system

d. Its education systemIts school education system

Answer: (a). Its school education system

72. Polymorphism is possible in C language.

a. True

b. False

c. May be

d. , “Can’t say”

Answer: (a). True

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

Answer: (c). All the derived classes must implement the undefined functions

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

Answer: (d). Increases overhead of function definition always

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

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

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

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

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

Answer: (a). Create public member functions to access those data members

78. While using encapsulation, which among the following is possible?

a. Code modification can be additional overhead

b. Data members data type can be changed without changing any other code

c. Data members 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

Answer: (b). Data members data type can be changed without changing any other code

79. Which feature can be implemented using encapsulation?

a. Inheritance

b. Abstraction

c. Polymorphism

d. Overloading

Answer: (b). Abstraction

80. 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 name10; public : int marks; }

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

81. Encapsulation helps in writing ___________ classes in java

a. Mutable

b. Abstract

c. Wrapper

d. Immutable

Answer: (d). Immutable

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

Answer: (a). The data which is prone to change is near future

83. How can Encapsulation be achieved?

a. Using Access Specifiers

b. Using only private members

c. Using inheritance

d. Using Abstraction

Answer: (a). Using Access Specifiers

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

a. Local variables

b. Global variables

c. Public variables

d. Array variables

Answer: (b). Global variables

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

Answer: (a). Using access declaration for private members of base class

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

Answer: (d). Using any kind of pointer/array address in passing to another function

87. Consider the following code and select the correct option:class student{  int marks; public : int* fun() {  return &marks; }};main(){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

Answer: (d). This code violates encapsulation

88. Consider the code and select the wrong choice:class hero{ char name10; public : void disp() {  cout<<name; }};

a. This maintains encapsulation

b. This code doesn’t maintain encapsulation

c. This code is vulnerable

d. This code gives error

Answer: (a). This maintains encapsulation

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

a. True

b. False

c. May be

d. , “Can’t say”

Answer: (b). False

90. Using encapsulation data security is ___________

a. Not ensured

b. Ensured to some extent

c. Purely ensured

d. Very low

Answer: (b). Ensured to some extent

91. \tWhich 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

Answer: (d). Hiding the implementation and showing only the features

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

Answer: (a). Make the programming easy

93. Class is _________ abstraction

a. Object

b. Logical

c. Real

d. Hypothetical

Answer: (b). Logical

94. Object is ________ abstraction

a. Object

b. Logical

c. Real

d. Hypothetical

Answer: (c). Real

95. Abstraction gives higher degree of ________

a. Class usage

b. Program complexity

c. Idealized interface

d. Unstable interface

Answer: (c). Idealized interface

96. Abstraction can apply to:

a. Control and data

b. Only data

c. Only control

d. Classes

Answer: (a). Control and data

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

a. Class

b. Object

c. Inheritance

d. Interfaces

Answer: (b). Object

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

Answer: (c). Use abstraction whenever possible to avoid duplication

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

a. True

b. False

c. May be

d. , “Can’t say”

Answer: (b). False

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

Answer: (a). Binding and Hiding respectively

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

Answer: (a). Abstraction is called a stream and device is called a file

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

Answer: (c). Using public member functions to access and manipulate the data members

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

Answer: (d). Phone

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

a. Logical level

b. Physical level

c. View level

d. External level

Answer: (d). External level

105. Using higher degree of abstraction __________

a. May get unsafe

b. May reduce readability

c. Can be safer

d. Can increase vulnerability

Answer: (c). Can be safer