hicasct.files.wordpress.com file · Web viewC++ Objective Questions. ... How many classes can be...
Transcript of hicasct.files.wordpress.com file · Web viewC++ Objective Questions. ... How many classes can be...
Hindusthan College of Atrs and Science (Autonomous)C++ Objective Questions
1.Which was the first purely object oriented programming language developed?A) JavaB) C++C) SmallTalkD) Kotlin
ANSWER: C
2. Which of the following best defines a class?A) Parent of an objectB) Instance of an objectC) Blueprint of an objectD) Scope of an object
ANSWER: B
3. Who invented OOP?A) Alan KayB) Andrea FerroC) Dennis RitchieD) Adele Goldberg
ANSWER: A
4. What is the additional feature in classes that was not in structures?A) Data membersB) Member functionsC) Static data allowedD) Public access specifier
ANSWER: B
5. Which is not feature of OOP in general definitions?A) Code reusabilityB) ModularityC) Duplicate/Redundant dataD) Efficient Code
ANSWER: C
6. Which of the following concepts means determining at runtime what method to invoke?A) Data hidingB) Dynamic TypingC) Dynamic bindingD) Dynamic loading
ANSWER: C
7. Which Feature of OOP illustrated the code reusability?A) PolymorphismB) AbstractionC) EncapsulationD) Inheritance
ANSWER: D
8. Which language does not support all 4 types of inheritance?
A) C++B) JavaC) KotlinD) Small Talk
ANSWER: B
9. How many classes can be defined in a single program?A) Only 1B) Only 100C) Only 999D) As many as you want
ANSWER: D
10. When OOP concept did first came into picture?A) 1970B) 1980C) 1993D) 1995
ANSWER: A
11. Why Java is Partially OOP language?A) It supports usual declaration of primitive data typesB) It doesn’t support all types of inheritanceC) It allows code to be written outside classesD) It does not support pointers
ANSWER: A
12. Which concept of OOP is false for C++?A) Code can be written without using classesB) Code must contain at least one classC) A class must have member functions
D) At least one object should be declared in code
ANSWER: B
13. Which header file is required in C++ to use OOP?A) iostream.hB) stdio.hC) stdlib.hD) OOP can be used without using any header file
ANSWER: D
14. Which of the two features match each other?A) Inheritance and EncapsulationB) Encapsulation and PolymorphismC) Encapsulation and AbstractionD) Abstraction and Polymorphism
ANSWER: C
15. Which feature allows open recursion, among the following?A) Use of this pointerB) Use of pointersC) Use of pass by valueD) Use of parameterized constructor
ANSWER: A
16. Which of the following is not type of class?A) Abstract ClassB) Final ClassC) Start ClassD) String Class
ANSWER: C
17. Class is pass by _______A) ValueB) ReferenceC) Value or Reference, depending on programD) Copy
ANSWER: B
18. Which is known as generic class?A) Abstract classB) Final classC) Template class
D) Efficient Code
ANSWER: C
19. Which class can have member functions without their implementation?A) Default classB) String classC) Template classD) Abstract class
ANSWER: D
20. What is scope of a class nested inside another class?A) Protected scopeB) Private scopeC) Global scopeD) Depends on access specifier and inheritance used
ANSWER: D
21. Which of the following access specifier is used as a default in a class definition?
A) protectedB) publicC) privateD) friend
ANSWER: C
22. Which of the following pairs are similar?A) Class and objectB) Class and structureC) Structure and objectD) Structure and functions
ANSWER: B
23. Instance of which type of class can’t be created?A) Anonymous classB) Nested classC) Parent classD) Abstract class
ANSWER: D
24. How many objects can be declared of a specific class in a single program?A) 32768B) 127
C) 1D) As many as you want
ANSWER: D
25. What is size of the object of following class (64 bit system)?class student { int rollno; char name[20]; static int studentno; };A) 20B) 22C) 24D) 28
ANSWER: C
26. Which of the following cannot be passed to a function in C++ ?A) ConstantB) StructureC) ArrayD) Header file
ANSWER: D
27. Which of the following is not a correct statement?A) Every class containing abstract method must be declared abstract.B) Abstract class can directly be initiated with ‘new’ operator.C) Abstract class can be initiated.D) Abstract class does not contain any definition of implementation.
ANSWER: B
28. A member function can always access the data in __________ , (in C++).A) the class of which it is memberB) the object of which it is a memberC) the public part of its classD) the private part of its class
ANSWER: A
29. Which of the following is not the member of class?
A) Virtual functionB) Static functionC) Friend functionD) Const function
ANSWER:C
30. Values that are used to end loops are referred to as _____ values.A) stopB) sentinelC) endD) finish
ANSWER: B
31. Which of the following type casts will convert an Integer variable named amount to a Double type ?A) (int to double) amountB) int (amount) to doubleC) int to double(amount)D) (double) amount
ANSWER: D
32. The static member functions __________________A) Have access to all the members of a classB) Have access to only constant members of a classC) Have access to only the static members of a classD) Have direct access to all other class members also
ANSWER:C
33. The keyword static is used _______________A) With declaration inside class and with definition outside the classB) With declaration inside class and not with definition outside the classC) With declaration and definition wherever doneD) With each call to the member function
ANSWER: B
34. The static data member _________________A) Can be mutableB) Can’t be mutableC) Can’t be integerD) Can’t be characters
ANSWER: B
35. Which among the following is true?A) Static member functions can’t be virtual
B) Static member functions can be virtualC) Static member functions can be declared virtual if it is pure virtual classD) Static member functions can be used as virtual in Java ANSWER: A
36.Which function cannot be overloaded in C++ program?
A) Virtual function B) member function C) Static function D) All can be overloaded
ANSWER:C
37. For overloading “( )”, “[ ]” or “->” operators, a class __________A) Must use static member functionsB) Must use non-static member functionsC) Must be non-static member and should not be friend of classD) Must use static member function or a friend member function
ANSWER: C
38. Which member function doesn’t require any return type?A) StaticB) ConstructorC) ConstD) Constructor and destructor
ANSWER:D
39. What is array of objects?A) An array of instances of class represented by single nameB) An array of instances of class represented by more than one nameC) An array of instances which have more than 2 instancesD) An array of instances which have different types
ANSWER:A
40. What is the type of the elements of array of objects?A) ClassB) VoidC) StringD) NullANSWER: A
41. How the objects of array can be denoted?A) IndicesB) NameC) Random numbersD) Alphabets
ANSWER:A
42. Which of the following access specifies is used in a class definition by default?A)ProtectedB)PublicC)PrivateD)Friend
ANSWER: C
43. The static member functions __________________A) Have access to all the members of a classB) Have access to only constant members of a classC) Have access to only the static members of a classD) Have direct access to all other class members also
ANSWER:C
44. Which of the following keywords is used to control access to a class member?A)DefaultB)BreakC)protectD)Asm
ANSWER: C
45. Which of the following type of data member can be shared by all instances of its class?A)PublicB)InheritedC)StaticD)Friend
ANSWER: C
46. Constructor is executed when _____.A)an object is createdB)an object is usedC)a class is declaredD)an object goes out of scope.
ANSWER:A
47. How many objects can be created from an abstract class?A)ZeroB)OneC)TwoD)As many as we want
ANSWER: A
48. Which of the following can be overloaded?A)ObjectB)FunctionsC)OperatorsD)Both B and C
ANSWER:D
49. What does a class hierarchy depict?A)It shows the relationships between the classes in the form of an organization chart.B)It describes "has a" relationships.C)It describes "kind of" relationships.D)It shows the same relationship as a family tree.
ANSWER: C
50. Which of the following statements about virtual base classes is correct?A)It is used to provide multiple inheritance.B)It is used to avoid multiple copies of base class in derived class.C)It is used to allow multiple copies of base class in a derived class.D)It allows private members of the base class to be inherited in the derived class.
ANSWER: B
51. The ……………. inherits some or all of the properties of the ……….. class. A) base, derivedB) derived, baseC) derived, initialD) base, final
ANSWER: B
52. A derived class with only one base class is called …………… inheritance. A) singleB) multipleC) multilevelD) hierarchical
ANSWER: A
53. A class can inherit properties from more than one class which is known as ……….inheritance.A) singleB) multipleC) multilevelD) hierarchical
ANSWER: B
54. A class can be derived from another derived class which is known as ………. inheritance. A) singleB) multipleC) multilevelD) hierarchical
ANSWER: C
55. When the properties of one class are inherited by more than one class, which is called ……… inheritance. A) singleB) multipleC) multilevelD) hierarchical
ANSWER: D
56. When a base class is privately inherited by a derived class public members of the base class become ………. of the derived class. A) private membersB) protected membersC) Public membersD) Not inherited
ANSWER: A
57. When a base class is privately inherited by a derived class public members of the base class can only be accessed by the ……… of the derived class. A) non-member functionsB) friend functionsC) member functionsD) class members
ANSWER: C
58. When a protected member is inherited in public mode, it becomes ……….. in the derived class too and therefore is accessible by member functions of the derived class.
A) protectedB) privateC) publicD) friend
ANSWER: A
59. Which type of inheritance leads to diamond problem?a) Single levelb) Multi-levelc) Multipled) Hierarchical
ANSWER: C
60. A member declared as ………….. is accessible by the member functions within its class and any class immediately derived from it.A) protectedB) privateC) publicD) friend
ANSWER: A
61. When the base class is publicly inherited, public members of the base class become …………. of the derived class. A) private membersB) protected membersC) Public membersD) Not inherited
ANSWER: C
62. In protected derivation, both the public and protected members of the base class become …………. members of the derived class. A) protectedB) privateC) publicD) friend
ANSWER: A
63. What will be the order of execution of base class constructors in the following method of inheritance. class A: public B, public C {….};A) B(); C(); A();B) C(); B(); A();C) A(); B(); C();D) B(); A(); C();
ANSWER: A
64. What will be the order of execution of base class constructors in the following method of inheritance. class A: public B, virtual public C {….};A) B(); C(); A();B) C(); B(); A();C) A(); B(); C();D) B(); A(); C();
ANSWER: B
65. While the friend functions and the member functions of a friend class can have direct access to both the private and protected data, the member functions of a derived class can directly access only the ………… data. A) protectedB) privateC) publicD) friend
ANSWER: A
66. In ……………………. inheritance, the constructors are executed in the order of inheritance.A) multipathB) multipleC) multilevelD) hierarchical
ANSWER: C
67. In ……………… inheritance, the base classes are constructed in the order in which they appear in the deceleration of the derived class. A) multipathB) multipleC) multilevelD) hierarchical
ANSWER: B
68. ……………… inheritance may lead to duplication of inherited members from a ‘grandparent’ base class.A) multipathB) multipleC) multilevelD) hierarchical
ANSWER: A
69. The member functions of a derived class can directly access only the ……………… data.
A) private and protectedB) private and publicC) protected and publicD) private, protected and public
ANSWER: C
70. The friend functions and the member functions of a friend class can directly access the ………………. data.A) private and protectedB) private and publicC) protected and publicD) private, protected and public
ANSWER: A
71.While overloading binary operators using member function, it requires ___ argument/s. A) ZeroB) OneC) TwoD) Three
ANSWER: B
72.In case of operator overloading, operator function must be ______ .
1) Static member functions2) Non- static member functions3) Friend Functions
A) Only 2B) Only 1, 3C) Only 2 , 3D) All 1 , 2, 3
ANSWER: C
73. Scope resolution operator is used______ .
A) to resolve the scope of global variables onlyB) to resolve the scope of functions of the classes onlyC) to resolve scope of global variables as well as functions of the classesD) None of these
ANSWER: C
74. ___________ header file is used for manipulators.
A) < iomanipulator.h>B) < stdiomanip.h>C) < stdmanip.h>D) < iomanip.h>
ANSWER: D
75.Which of the following is not a casting operator in CPP? A) explicit_castB) static_castC) dynamic_castD) reinterpret_cast
ANSWER: A
76. In compile time polymorphism, compiler is able to select the appropriate function for a particular call at the compile time itself, which is known as …………A) Early BindingB) Static BindingC) Static LinkingD) All of The Above
ANSWER: D
77. ……………. binding means that, an object is bound to its function call at compile time.A) LateB) StaticC) DynamicD) Fixed
ANSWER: B
78. C++ supports run time polymorphism with the help of virtual functions, which is called …………….. binding.A) DynamicB) Run TimeC) Early BindingD) Static
ANSWER: A
79. State whether the following statements about pointers in C++ are True.
I) A Pointer Can Be Incremented (++) Or Decremented (–)Ii) Any Integer Can Be Added to Or Subtracted From A PointerIii) One Pointer Can Be Subtracted From Another
A) I And Ii OnlyB) Ii And Iii OnlyC) I And Iii OnlyD) All I, Ii And Iii
ANSWER: D
80. ………………. are also known as generic pointers, which refer to variables of any type.A) Void PointersB) Null PointersC) This PointerD) Base Pointer
ANSWER: A
81. The pointers which are not initialized in a program are called ……………..A) Void PointersB) Null PointersC) This PointerD) Base Pointer
ANSWER: B
82. …………………… is useful in creating objects at run time.A) Void PointerB) Null PointerC) This PointerD) Object Pointer
ANSWER: D
83. A …………………. refers to an object that that currently invokes a member function.A) Void PointersB) Null PointersC) This PointerD) Base Pointer
ANSWER: C
84. The …………………. cannot be directly used to access all the members of the derived class.A) Void PointersB) Null PointersC) This Pointer
D) Base Pointer
ANSWER: D 85. Run time polymorphism is achieved only when a ……………….. is accessed through a pointer to the base class.A) Member FunctionB) Virtual FunctionC) Static FunctionD) Real Function
ANSWER: B
86. If a ……………………… is defined in the base class, it need not be necessarily redefined in the derived class.A) Member FunctionB) Virtual FunctionC) Static FunctionD) Real Function
ANSWER: B
87. …………………………. is a function declared in a base class that has no definition relativeto the base class.A) Member FunctionB) Virtual FunctionC) Pure Virtual FunctionD) Pure Function
ANSWER: C
88. A class that have no pure virtual member functions, are called
A) Polymorphic classB) Concrete classC) Base classD) Abstract class
ANSWER: B
89. The main objective of an abstract base class is to provide some traits to the derived class and to create a ………………………. required for achieving run time polymorphism.A) Void PointersB) Null PointersC) This PointerD) Base Pointer
ANSWER: D
90. State whether the following statements about virtual functions is/are True.I) The Virtual Function Must Be Member Of Some ClassIi) Virtual Functions Cannot Be Static MembersIii) A Virtual Function Can Not Be A Friend Of Another Class.
A) I And Ii OnlyB) Ii And Iii OnlyC) I And Iii OnlyD) All I, Ii And Iii
ANSWER: A
91. The important application of ………………… is to return the object it points to.A) Void PointersB) Null PointersC) This PointerD) Base Pointer
ANSWER: C
92. The pointer to function is known as …………………. function.A) ForwardB) PointerC) CallbackD) Backward
ANSWER: C
93. We can manipulate a pointer with the indirection operator (*), which is also known as ……………………A) Reference OperatorB) Dereference OperatorC) Direction OperatorD) Indirection Operator
ANSWER: B
94. Using the ………………………., we can change the contents of the memory location.A) Reference OperatorB) Dereference OperatorC) Direction OperatorD) Indirection Operator
ANSWER: B
95. If we attempt to dereference an uninitialized pointer, it will ………………….. by referring to any other location in memory.A) Cause Compile Time ErrorB) Run Time ErrorC) Cause Run Time ErrorD) Executes
ANSWER: C
96. Which of these best describes an array?A) A Data Structure That Shows A Hierarchical BehaviorB) Container Of Objects Of Similar TypesC) Container Of Objects Of Mixed TypesD) All Of The Mentioned
ANSWER: B
97. How do you initialize an array in C?A) Int Arr[3] = (1,2,3);B) Int Arr(3) = {1,2,3};C) Int Arr[3] = {1,2,3};D) Int Arr(3) = (1,2,3);
ANSWER: C
98. Each element of an array is searched against searching key, is specialty of _______.A) Bubble SortB) Linear SearchC) Binary SearchD) All Of Them
ANSWER: B
99. A one-dimensional array of one-dimensional arrays is called____A) Multi-Dimensional ArrayB) Multi-Casting ArrayC) Two-Dimensional ArrayD) Three-Dimensional Array
ANSWER: C
100. Which of the following accesses the seventh element stored in array?A) Array[6];B) Array[7];C) Array(7);D) Array;
ANSWER: A
101. In context to file handling, which of the following are file handling operations?A) OpeningB) ClosingC) Read/WriteD) All of Above
ANSWER: D
102. Which of the following methods can be used to open a file in file handling?A) Using Open ( )B) Constructor MethodC) Destructor MethodD) Both A And B
ANSWER: D
103. To perform File I/O operations, Which of the following header files is used?A. ≪ Ifstream≫B. ≪ Ofstream≫C. ≪ Fstream≫D. Any Of These
ANSWER: C
104) Out of the following options, object of which class is declared in order to create an output streamA) OfstreamB) IfstreamC) IostreamD) None Of These
ANSWER: A
105. In which of the following classes, Streams that will be performing both input and output operations must be declared?A) IostreamB) FstreamC) StdstreamD) Stdiostream
ANSWER: B
106. Which of the following is not a file opening mode?A) Ios::AteB) Ios::NocreateC) Ios::Noreplace
D) Ios::Truncate
ANSWER: D
107. By default, all the files are opened in which of the following mode?A) Binary ModeB) Text ModeC) Sequential ModeD) Both A And B
ANSWER: B
108. If we have object from fstream class, then what will be the default mode of opening the file?A) Ios::In|Ios::OutB) Ios::In|Ios::Out|Ios::TruncC) Ios::In|Ios::TruncD) Default Mode Depends On Compiler
ANSWER: D
109. Which out of the following is return type of is_open() function.A) IntB) BoolC) FloatD) Char *
ANSWER: B
110. Which of the following is not used to seek a file pointer?A) Ios::CurB) Ios::SetC) Ios::EndD) Ios::Beg
ANSWER: B
111. Which of the following options is in relevance to ios::trunc mode?A) If The File Is Opened For Output Operations And It Already Existed, No Action Is Taken.B) If The File Is Opened For Output Operations And It Already Existed, Its Previous Content Is Deleted And Replaced By The New One.C) If The File Is Opened For Output Operations And It Already Existed, Then A New Copy Is Created.D) None Of Above
ANSWER: B
112. Which of the following option shows correct syntax for opening a file ?
A) Myfile:Open (&Quot;Example.Bin&Quot;, Ios::Out);B) Myfile.Open (&Quot;Example.Bin&Quot;, Ios::Out);C) Myfile::Open (&Quot;Example.Bin&Quot;, Ios::Out);D) Myfile.Open (&Quot;Example.Bin&Quot;, Ios:Out);
ANSWER: B
113.Which Of The Following Is Correct Syntax For Closing A File In C++ ?A) Myfile$Close();B) Myfile@Close();C) Myfile:Close();D) Myfile.Close();
ANSWER: D
114. Which of the given options tells about the use of eof( ) stream function ?A) Returns True If A File Open For Reading Has Reached The Next Character.B) Returns True If A File Open For Reading Has Reached The Next Word.C) Returns True If A File Open For Reading Has Reached The End.D) Returns True If A File Open For Reading Has Reached The Middle.
ANSWER: C
115. Which of the following functions allow to change the location of the get and put positions ?A) Sg() And Sp()B) Sekg() And Sekp()C) Gog() And Gop()D) Seekg() And Seekp()
ANSWER: D
116. which of the following is used for offset counted from the current position?A) Ios::CurrB) Ios::CrC) Ios::CurD) Ios::Current
ANSWER: C
117. Which of the following is used for positioning relative to the beginning of a stream ?A) Ios::StartB) Ios::BegC) Ios::BeginD) Ios::Beginning
ANSWER: B
118. Which of the following is used to Open a file for output and move the read/write control tothe end of the file ?A) Ios::AteB) Ios::AtC) Ios::AnnD) Ios::End
ANSWER: A
119. Which is correct syntax for, position n bytes back from end of fileObject ?A) Fileobject.Seekg(Ios::End, N);B) Fileobject.Seekg(N, Ios:End );C) Fileobject.Seekg(N, Ios::End );D) Fileobject.Seekg(Ios:End, N);
ANSWER: C
120.How to find the position at end of fileObject ?A) Fileobject.Seekg( 0, Ios::End );B) Fileobject.Seekg( 0, Ios::End );C) Fileobject.Seekg( 0, Ios::End );D) Fileobject.Seekg( 0, Ios::End );
ANSWER: A
121. How to get position n bytes forward in fileObject ?A) Fileobject.Seekg( Ios::Cur, N );B) Fileobject.Seekg( N, Ios:Cur );C) Fileobject.Seekg( N, Ios::Cur );D) Fileobject.Seekg( Ios:Cur, N );
ANSWER: C
122. How to get position to the nth byte of fileObject ?
A) Fileobject.Seekg( 'Filename',N );B) Fileobject.Seekg( N, 'Filename' );C) Fileobject.Seekg( N );D) Fileobject.Seekg( N, Ios::App );
ANSWER: C
123.There are how many types of stream operators?A) 1B) 2C) 3
D) 4
ANSWER: B
124.Which operators used when one object is assigned to another object that has already been declared for same class?A) Logical operatorB) Assignment operatorC) Relational operatorD) None of them
ANSWER: B
125.All these strncpy ( ), strstr ( ), strok( ), strchr ( ) functions belongs toA) ≪Str.H≫ FileB) ≪Ctype.H≫ FileC) ≪Array.H≫ FileD) ≪String.H≫ File
ANSWER: D