This document contains 60 multiple choice questions related to object-oriented programming concepts in C++. The questions cover topics such as classes, objects, encapsulation, inheritance, polymorphism, and more. Key concepts assessed include types of constructors, friend functions, dynamic binding, data hiding, abstract classes, and differences between classes and structures.
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 ratings0% found this document useful (0 votes)
133 views34 pages
Unit1 Mcqs
This document contains 60 multiple choice questions related to object-oriented programming concepts in C++. The questions cover topics such as classes, objects, encapsulation, inheritance, polymorphism, and more. Key concepts assessed include types of constructors, friend functions, dynamic binding, data hiding, abstract classes, and differences between classes and structures.
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/ 34
1) Which of the following is not a type of constructor?
A. Copy constructor B. Friend constructor C. Default constructor D. Parameterized constructor Answer: B
2) Which of the following is not the member of class?
A. Static function B. Friend function C. Const function D. Virtual function Answer: B
3) Which of the following concepts means determinin
g at runtime what method to invoke? A. Data hiding B. Dynamic Typing C. Dynamic binding D. Dynamic loading Answer: C 4) The friend functions are used in situations wher e: A. We want to have access to unrelated classes B. Dynamic binding is required C. Exchange of data between classes to take pl ace D. None of the above Answer: D 5) The keyword friend does not appear in A. The class allowing access to another class B. The class desiring access to another class C. The private section of a class D. The public section of a class Answer: C 6) The term __________ means the ability to take ma ny forms. A. Inheritance B. Polymorphism C. Member function D. Encapsulation Answer: B 7) C++ was originally developed by A. Clocksin and Melish B. Donald E.Knuth C. Sir Richard Hadlee D. Bjarne Stroustrup Answer: D 8) A variable defined within a block is visible A. From the point of definition onward in the program B. From the point of definition onward in the function C. From the point of definition onward in the block D. Throughout the function Answer: C 9) Which of the following term is used for a functi on defined inside a class? A. Member Variable B. Member function C. Class function D. Classic function Answer: B 10) Which of the following concept of oops allows compiler to insert arguments in a function call if it is not specified? A. Call by value B. Call by reference C. Default arguments D. Call by pointer Answer: C 11) How many instances of an abstract class can be created? A. 1 B. 5 C. 13 D. 0 Answer: D 12) Which of the following cannot be friend? A. Function B. Class C. Object D. Operator function Answer: C 13) Which of the following concepts of OOPS means exposing only necessary information to client? A. Encapsulation B. Abstraction C. Data hiding D. Data binding Answer: C 14) In structured programming, the problem is divid ed into various ______. A. modules B. functions C. structures D. objects Answer: B 15) In Object-oriented programming, the problem is divided into _____. A. classes & objects B. functions C. structures D. modules Answer: A 16) A class is ____ datatype. A. primitive B. derived C. user-defined D. All of these Answer: C 17) A class is a collection of ____ and_____. (A)data-members & member functions (B)data-members, member functions and main() (C) data-members, member functions,main() and inclu de statements (D)None of these Answer: A 18) An object is ...... (A)a variable of class datatype. (B)same as a class. (C)just like a global variable. (D)collection of data-members and member functions. Answer: A 19) Wrapping up of data & functions together in a c lass is known as _____. (A)Overloading (B) Data Abstraction (C)Polymorphism (D)Encapsulation Answer: D 20) Including only necessary details and ignoring additional details while defining a class is known as ____. (A) Overloading (B) Data Abstraction (C) Polymorphism (D) Encapsulation Answer: B 21) Preventing direct access of data-members of th e class from outside world is known as ____. (A)Polymorphism (B)Encapsulation (C)Data Hiding (D) scope resolution. Answer: C 22) What are cin and cout? (A) pointers (B) functions (C) operator (D) stream objects Answer: C 23) Which header file must be included for cin and cout? (A) stdio.h (B) conio.h (C) iostream.h (D) Both iostream.h and conio.h Answer: C 24) Creating a new class using one or more existing classes is known as ____. (A)Polymorphism (B)Encapsulation (C)overloading (D)inheritance Answer: D 25) Ability of an operator or function call to take different forms is known as ____. (A) Polymorphism (B) Encapsulation (C) overloading (D)inheritance Answer: A 26) cout is a/an __________ . A. operator B. function C. object D. macro Answer: C 27) Which of the following concepts provides facil ity of using object of one class inside another cl ass? A. Encapsulation B. Abstraction C. Composition D. Inheritance Answer: C 28) How many types of polymorphisms are supported b y C++? A. 1 B. 2 C. 3 D. 4 Answer: B 29) Which of the following is an abstract data type ? A. int B. double C. string D. Class Answer: D 30) A __________ is a special method used to initia lize the instance variable of a class. A. Member function B. Destructor C. Constructor D. Structure Answer: C 31) Which of the following concepts means adding ne w components to a program as it runs? A. Data hiding B. Dynamic typing C. Dynamic binding D. Dynamic loading Answer: D 32) Which of the following statement is correct? A. A constructor is called at the time of declarat ion of an object. B. A constructor is called at the time of use of a n object. C. A constructor is called at the time of declarat ion of a class. D. A constructor is called at the time of use of a class. Answer: A 33) Which of the following approach is adapted by C ++? A. Top-down B. Bottom-up C. Right-left D. Left-right Answer: B 34) Which of the following is correct about class a nd structure? A. class can have member functions while structure cannot. B. class data members are public by default while that of structure are private. C. Pointer to structure or classes cannot be decla red. D. class data members are private by default whil e that of structure are public by default. Answer: D 35) Which of the following concepts means wrapping up of data and functions together? A. Abstraction B. Encapsulation C. Inheritance D. Polymorphism Answer: B 36) Which of the following concepts means waiting until runtime to determine which function to call? A. Data hiding B. Dynamic casting C. Dynamic binding D. Dynamic loading Answer: C 37) Which of the following operator is overloaded f or object cout? A. >> B. << C. + D. = Answer: B 39) Which of the following is the correct class of the object cout? A. iostream B. istream C. ostream D. ifstream Answer: C 40) Which of the following cannot be used with the keyword virtual? A. class B. member functions C. constructor D. destructor Answer: C 41) Which of the following functions are performed by a constructor? A. Construct a new class B. Construct a new object C. Construct a new function D. Initialize objects Answer: D 42) Which of the following is the correct way of de claring a function as constant? A. const int ShowData(void) { /* statements */ } B. int const ShowData(void) { /* statements */ } C. int ShowData(void) const { /* statements */ } D. Both A and B Answer: C 43) Which of the following statement is correct? A. C++ allows static type checking. B. C++ allows dynamic type checking. C. C++ allows static member function be of type co nst. D. Both A and B. Answer: D 44) Which of the following header file includes def inition of cin and cout? A. istream.h B. ostream.h C. iomanip.h D. iostream.h Answer: D 45) What will happen if a class is not having any n ame? A. It cannot have a destructor. B. It cannot have a constructor. C. It is not allowed. D. Both A and B. Answer: D 46) Which one of the following is correct about the statements given below? All function calls are resolved at compile-time in Procedure Oriented Programming. All function calls are resolved at compile-time in OOPS. A. Only II is correct. B. Both I and II are correct. C. Only I is correct. D. Both I and II are incorrect. Answer: C 47) Which one of the following options is correct? A. Friend function can access public data members of the class. B. Friend function can access protected data membe rs of the class. C. Friend function can access private data members of the class. D. All of the above. Answer: D 48) Which of the following statements is correct in C++? A. Classes cannot have data as protected members. B. Structures can have functions as members. C. Class members are public by default. D. Structure members are private by default. Answer: B 49) Which of the following access specifier is used as a default in a class definition? A. protected B. public C. private D. friend Answer: C 50) What is correct about the static data member of a class? A. A static member function can access only static data members of a class. B. A static data member is shared among all the ob ject of the class. C. A static data member can be accessed directly f rom main(). D. Both A and B. Answer: D 51) Which of the following provides a reuse mechani sm? A. Abstraction B. Inheritance C. Dynamic binding D. Encapsulation Answer: B 53) Which of the following statement is correct? A. Class is an instance of object. B. Object is an instance of a class. C. Class is an instance of data type. D. Object is an instance of data type. Answer: B 53) The process of building new classes from existi ng one is called A. Structure B. Inheritance C. Polymorphism D. Template Answer: B 54) In a class, member variables are often called its _________, and its member functions are someti mes referred to as its behaviour, or ____________. A. attributes, methods B. none of these C. values, morals D. data, activities Answer: A 55) Which of these keywords are access specifiers? A. near and far B. opened and closed C. table and row D. private and public Answer: D 56) An Object can be declared prior to the class de finition A. True B. False: Answer: False 57) Use of __________ protects data from inadverten t modifications A. protect() member function B. private access specifier C. class protection operator, @ D. none of these Answer: B 58) A suitable place to store Class declarations is _______. A. none of these B. their own header files C. Auxiliary .cpp file D. main .cpp files, along with function definiti ons Answer: B 59) Inline Functions are invoked at A. Run time B. Compile time C. Depends on how it is invoked D. Both b and c above Answer: B 60) which of the following operator is used to defi ne member function outside the class? A. :: B. ? C. :? D. % Answer: A 61) function call mechanism that passes arguments to a function by passing a copy of the values of t he arguments is __________ (A)call by name (B)call by value (C)call by reference (D)call by value result Answer: B 62) Data members which are static (A)cannot be assigned a value (B)can only be used in static functions (C)cannot be defined in a Union (D) can be accessed outside the class Answer: B 63) Which of the following is false for cin? (A)It represents standard input. (B)It is an object of istream class. (C)It is a class of which stream is an object. (D)Using cin the data can be read from user’s termi nal Answer: C 64) It is possible to declare as a friend (A) a member function (B) a global function (C) a class (D) all of the above Answer: D 65) Given a class named Book, which of the followin g is not a valid constructor? (A)Book ( ) { } (B)Book ( Book b) { } (C)Book ( Book &b) { } (D)Book (char* author, char* title) { } Answer: B 66) How many constructors can a class have? (A) 0 (B) 1 (C) 2 (D) any number Answer: D 66) The new operator A) returns a pointer to the variable B) creates a variable called new C) obtains memory for a new variable D) tells how much memory is available Answer: C 67) A static function A. should be called when an object is destroyed B. is closely connected with and individual object of a class C. can be called using the class name and function name D. is used when a dummy object must be created Answer: C 68) We can output text to an object of class ostrea m using the insertion operator<< because (A) the ostream class is a stream (B) the insertion operator works with all classes (C) we are actually outputting to cout (D) the insertion operator is overloaded in ostream Answer: D 69) Which of the following is not the characteristi c of constructor ? (A) They should be declared in the public section. (B) They do not have return type. (C) They can not be inherited. (D) They can be virtual. Answer: D 70) A class defined within another class is: (A) Nested class (B) Inheritance (C) Containership (D) Encapsulation Answer: A 71) Which of the following statements are true in c ++? (A) Classes can not have data as public members (B) Structures can not have functions as members (C) Class members are public by default (D) None of these Answer: B 72) The following can be declared as friend in a cl ass (A) an object (B) a class (C) a public data member (D) a private data member Answer: B 73) A copy constructor takes (A) no argument (B) one argument (C) two arguments (D) arbitrary no. of arguments Answer: B 74) Which can be passed as an argument to a functio n? (A) constant (B) expression (C) another function (D) all of the above. Answer: A 75) Member functions, when defined within the class specification: (A) are always inline. (B) are not inline. (C) are inline by default, unless they are too big or too complicated. (D) are not inline by default. Answer: A 76) An entity representing some characteristics and behaviour isa) object b) class c) struct d) none of the above Answer: A 77) Which of the following is not the feature of OO Ps? a) Data Encapsulation b) Inheritance c) Polymorphism d) None of the above Answer: D 78) The wrapping up of data and functions into a si ngle unit is a) Data Abstraction b) Data Encapsulation c) Both (a) & (b) d) None of the above Answer: B 79) Which of the following feature supports reusabi lity and extensibility of classes? a) Inheritance b) Overloading c) Polymorphism d) None of the above Answer: A 80) Inheritance is ………..in nature. a) Intransitive b) Transitive c) Both (a) & (b) d) None of the above Answer: B 81) ………… is the ability for a message or data to be processed in more than one form a) Class b) Abstraction c) Polymorphism d) None of the above Answer: C 82) The smallest individual unit in a program is …… … a) Keyword b) Identifier c) Token d) None of the above Answer: C 83) Which of the following features of procedure or iented programming is false a) Large programs are divided into small or units c alled functions. b) Employs bottom-up approach in program design. c) Most of the functions share global data. d) None of the above. Answer: B 84) Which of the following features of object orien ted programming is false? a) Data is hidden and is not available to external functions. b) New data & functions can be added easily. c) Objects may communicate with each other through functions. d) Emphasis is on the procedure rather than data. Answer: D 85) The following is the C++ style comment a) // b) /*..*/ c) – d) None of the above Answer: A 86) Which of the following statements is false? a) Every C++ program must have a main(). b) In C++, white spaces and carriage returns are ig nored by the compiler. c) C++ statements terminate with semicolon. d) Main() terminates with semicolon. Answer: D 87) An identifier in C++ a) Must begin with a letter only b) Is not differentiated by cases c) Contains all characters as significant d) None of the above Answer: C 88) ………. Provides a value for a variable a) declaration statement b) assignment statement c) definition statement d) None of the above Answer: B 89) A collection of variables referred under one na me a) Structure b) Class c) Union d) None of the above Answer: A 90) A memory location shared by two or more differe nt variables a) Structure b) Class c) Union d) None of the above Answer: C 91) The constants defined using enum keyword are a) Symbols b) Enumerators c) Keywords d) None of the above Answer: B 92) The operator ?: is a) Logical operator b) Relational operator c) Conditional operator d) Arithmetic operator Answer: C 93) A loop containing other loop is a) Nested b) Inner c) Outer d) None of the above Answer: A 94) The following statement forces the next iterati on of the loop to take place a) break b) continue c) goto d) None of the above Answer: B 95) gets() function is available in a) stdio.h b) string.h c) ctype.h d) stdlib.h Answer: A 96) In C++, the statements are enclosed within a) parenthesis b) square brackets c) curly brackets d) None of the above Answer: C 97) The following tells the compiler where the prog ram begins a) Function prototype b) Forward declaration of class c) main() d) None of the above Answer: C 98) << operator is a) stream insertion operator b) stream extraction operator c) left shift operator d) None of the above Answer: A 99) “H” is an example of a) character literal b) string literal c) variable d) None of the above Answer: B 100) Which of the following statements regarding co mments is false? a) /*..*/ b) Comment beginning with // extends to the end of the line c) Comments may be nested d) Comments are used to describe a program Answer: C 101) C++ is a) Procedural programming language b) Structural programming language c) Object oriented programming language d) None of the above Answer: C 102) y=x=2; in C++ will result in a) compilation error b) runtime error c) assignment of value to x then to y d) None of the above Answer: C 103) 31. In C++, ………. is the statement terminator a) semicolon b) colon c) new line d) None of the above Answer: A 104) Modules operator (%) has higher precedence tha n a) Divide (/) operator b) Multiply (*) operator c) Negation (unary minus) d) Bitwise left shift operator Answer: C 105) The result of the following statement is int y = 7; int ans = ++y; cout<<”ans=”<<ans; cout<<”y”<<y; a) ans=7, y=7 b) ans=8,y=7 c) ans=8,y=8; d) none of the above Answer: C 106) Consider the following if construct If(x=0) cout<<”Inside loop!”; cout<<”Outside loop”; The result of the above code segment is. a) inside loop b) outside loop c) both (a) & (b) d) none of the above Answer: B 107) The result of 2 & 3 is a) 2 b) 3 c) 5 d) none of the above Answer: A 108) Which of the following statements regarding en umerators is false? a) Enumeration is an alternative method for naming integer constants/ b) An enumerator value can’t be changed in a progra m c) An integer value may be assigned to an enumerate d variable d) An enum defined within a structure is local to t he structure Answer: C 109) Which of the following statements is false? a) typedef defines new data types b) Using typedef does not replace the standard C++ data type name with the new name c) The new name defined by typedef, can be used as a type for another typedef d) None of the above Answer: A 110) Data members and member functions are enclosed within a) class b) structure c) union d) None of the above Answer: A 111) Inline functions are a) Declared in the class defined outside the class b) Defined outside the class using keyword intime c) Defined inside the class using keyword inline d) None of the above Answer: B 112) The default class access scope is a) Private b) Public c) Protected d) None of the above Answer: A 113) The default scope for a structure is a) Private b) Public c) Protected d) None of the above Answer: B 114) The private data members of a class are access ible a) Directly to objects of that class b) Only to the member functions c) To any function defined outside a class d) None of the above Answer: B 115) The objects can directly access a) Public members b) Private members c) Both (a) & (b) d) None of the above Answer: A 116) The following is a valid statement in C++ a) int x=(int)2.50; b) int x=int(2.50); c) Both (a) & (b) d) None of the above Answer: C 117) Which of the following operator can be overloa ded a) Member access operator ( . & .*) b) Conditional operator (?:) c) Scope resolution operator (::) d) None of the above Answer: D 118) Using same function name to perform different tasks is a) Function polymorphism b) Runtime polymorphism c) Function prototype d) None of the above Answer: A 119) Default argument is a) Specified in function definition b) Specified in function declaration c) Specified from left to right d) None of the above Answer: B 120) What is wrong with the following statement? float s_interest (float principal, int rate=0.25, i nt time); a) variables must not be specified in function prot otype b) arguments may only be defaulted from right to le ft c) the default value must be specified when making a function call d) none of the above Answer: B 121) Which of the following statements regarding fu nction overloading is not true. a) If is used to handle different data types at one place b) When making a function call, if no exact match is found, promotion is the only criteria to find a match. c) The default arguments can not be used instead of overloading d) Unrelated functions should not be overloaded Answer: C 122) The private members of a class implement the O OP concept of a) Data abstraction b) Data hiding c) Message passing d) None of the above Answer: B 123) When a member function of a class call another member function, it is a) Nesting of classes b) Nesting of functions c) Nesting of objects d) None of the above Answer: B 124) A function defined inside a class is called a) A class function b) A friend function c) A member function d) None of the above Answer: C 125) Information is made shareable through a) inheritance b) data encapsulation c) data abstraction d) none of the above Answer: A 126) Functions can returns a) arrays b) reference c) object d) all of the above Answer: D 127) The memory for date members is allocated a) When a class is defined b) When an object is initialized c) When an object is created d) None of the above Answer: B 128)The memory for member functions is allocated a) When a class is defined b) When a object is created c) When an object is initialized d) None of the above Answer: A 129) The dot operator relates a) A class member and a class object b) A class object and a class c) A class and a member of that class d) A class object and member of that class Answer: D 130) A class having another class definition is a) Nested class b) Subordinate class c) Enclosing class d) None of the above Answer: C 131) A class whose member functions are friends of other class is a) Friend class b) Abstract class c) Virtual class d) None of the above Answer: A 132) The data members of a class are initialized a) in class definition b) by a non-member function c) through constructor function when a class object is created d) none of the above Answer: C 133) A constructor function is a) A friend function to a class b) A member function with the same name as its clas s c) A non-member function d) None of the above Answer: B 134) An enumerated type is composed of a) Integer values with user defined name b) Variables of different data types c) Constant numeric values d) None of the above Answer: A 135) In C++, the arguments by default are passed by a) call be reference b) call be value c) both (a) & (b) d) none of the above Answer: B 136) is an example of a) unary operator b) binary operator c) ternary operator d) none of the above Answer: C 137) new operator is used a) to define a new variable b) to create a new data type c) to allocate memory dynamically d) none of the above Answer: C 138) A constructor function is generally defined a) In the public section of a class b) In the private section of a class c) In the protected section of a class d) None of the above Answer: A 139) A class having no public constructors is a) A private class b) A public class c) An abstract class d) None of the above Answer: A 140) If a constructor function is defined in privat e section of a class, then a) The object cannot be created b) Only member functions and friends may declare ob jects of the class c) Both (a) & (b) d) None of the above Answer: C 141) A constructor with no argument is a) Default constructor b) Parameterized constructor c) Copy constructor d) None of the above Answer: A 142) If default arguments are provided to a constru ctor function, then it becomes a) Default constructor b) Copy instructor c) Parameterized constructor d) None of the above Answer: A 143) The class of which the objects are not instant iated is a) Abstract class b) Virtual class c) Static class d) None of the above Answer: A 144) && denotes a) logical OR b) logical AND c) Bitwise AND d) None of the above Answer: B 145) The parameterized constructor a) Needs initial values as arguments during creatio n of an object b) Can be invoked explicitly only c) Can be invoked implicitly only d) None of the above Answer: A 146) Explicit call to a constructor means a) Providing the constructor name explicitly to inv oke it b) Not providing the construction name at all c) Is the shorthand method d) None of the above Answer: A 147) Classes in C++ are a) Fundamental data type b) Primitive data type c) Desired data type d) None of the above Answer: C 148) A copy constructor is called a) When an object is defined and initialized with a nother object b) When an object is passed by value c) When a function returns an object d) All of the above Answer: D 149) Which of the following regarding constructor f unction is false? a) Constructor functions don’t have return type, no t even void b) Constructors can’t be inherited c) We can refer to their addresses d) Constructors cannot be virtual Answer: C 150) If new operator is used, then the constructor function is a) Parameterized constructor b) Copy constructor c) Dynamic constructor d) Default constructor Answer: C 151) Which of the following statements regarding co nstructor is false? a) A constructor may be defined static b) Constructor can have default arguments c) Member functions may be invoked from within a co nstructor d) None of the above Answer: A 152) The antonym of constructor is a) Creator b) Destructor c) Destroyer d) None of the above Answer: B 153) Variable …………. of void type a) May be declared b) Cannot be declared c) Can be initialized d) None of the above Answer: B 154) A destruction function a) Takes no argument and has no return type not eve n void b) Has name similar to that of class, preceded by t ilde(~) symbol c) Is used to destruct an object, constructed throu gh constructor function d) All of the above Answer: D 155) Which of the following statements regarding de structor function is false? a) Destructors do not accept any arguments, nor do they return any values b) Destructors can be inherited c) Member functions may be called from within a des tructor d) Destructor functions are called automatically wh en an object is destroyed Answer: B 156) Function overloading a) Involves several function definitions under one name, but different argument types b) Implements polymorphism c) Reduces the number of comparison in a program, hence increases the execution speed of a program d) All of the above Answer: D 157) The signature of function is a) The number & type of arguments b) The return type of a function c) The class definition d) None of the above Answer: A 158) Overloading of constructor function a) is similar to function overloading b) different from an overloaded function as it can’ t return a value c) not permitted in C++ d) none of the above Answer: B 159) The binding of a function call at runtime is a) Static binding b) Early binding c) Late binding d) Runtime binding Answer: C 160) The process of giving special meaning to an op erator is a) Operator overloading b) Operator mechanism c) Operator definition d) None of the above Answer: A 161) What is a comment in c++? a) comments are parts of the source code disregarde d by the compiler b) comments are executed by compiler to find the me aning of the comment c) comments are executable d) none of the mentioned Answer: a 162) What type of comments does c++ support? a) single line b) multi line c) single line and multi line d) none of the mentioned Answer: C 163) What is the use of the indentation in c++? a) distinguishes between comments and code b) r distinguishes between comments and outer data c) both a and b d) none of the mentioned Answer: A