C++ Object-Oriented Programming Quiz
C++ Object-Oriented Programming Quiz
com
1
contact@[Link] 9910707562
C++ Assignment S P SHARMA CLASSES [Link]
29.) A function that is called automatically A.) all of its members are inherited
each time an object is destroyed is a B.) all of its members are inherited, except
A.) constructor for any private members
B.) destructor C.) all of its members are inherited, except
C.) destroyer for any protected members
D.) terminator D.) None of its members is inherited
unless specifically listed
30.) class X, class Y and class Z are
derived from class BASE. This ..... 36.) If we create a file by 'ifstream', then
inheritance. the default mode of the file is .....
A.) multiple A.) ios :: out
B.) multilevel B.) ios :: in
C.) hierarchical C.) ios :: app
D.) single D.) ios:: binary
31.) The derivation of Child class from 37.) To perform file I/O operations, we
Base class is indicated by ..... symbol must use ..... header file,
A.) :: A.) <ifstream>
B.) : B.) <ofstream>
C.) ; C.) <fstream>
D.) | D.) Any of these
32.) When a base class is privately 38.) To create an output stream, we must
inherited by the derived class, then ..... declare the stream to be of class .....
A.) ofstream
A.) protected members of the base class
B.) ifstream
become private members of derived class C.) iostream
B.) public members of the base class D.) None of these
become private members of derived class
C.) Both (A) and (B) 39.) Which of the following is not a file
D.) Only B opening mode?
A.) ios:out
33.) Inheritance is the principle that B.) ios::in
A.) classes with the same name must be C.) ios::app
derived from each another D.) ios::truncate
B.) knowledge of a general category can
be applied to more specific objects 40.) ..... is return type of is_open() function.
C.) C++ functions may be used only if A.) int
B.) bool
they have' logical predecessors
C.) float
D.) one function name may invoke D.) char*
different methods
41.) Which of the following is not used to seek
34.) Which of the following is true? a file pointer?
A.) A derived class may have more than A.) ios::cur
one base class B.) c:ios::end
B.) A base class may have more than one C.) ios::set
derived class D.) ios:beg
C.) Both (A) and (B)
D.) A base class is not a super class 42.) Which among following is correct syntax
of closing a file in C++?
35.) When a class serves as a base class to A.) myfile$close();
B.) myfile@close();
others, .....
3
contact@[Link] 9910707562
C++ Assignment S P SHARMA CLASSES [Link]
43.) What is the use of eof()? 50.) What does the following statement mean?
A.) Returns true if a file open for reading has int(*fp)(char*)
reached the next character. A.) pointer to a pointer
B.) Returns true if a file open for reading has B.) pointer to an array of chars
reached the next word. C.) pointer to function taking a char*
C.) Returns true if a file open for reading has argument and returns an int
reached the end. D.) function taking a char* argument and
D.) Returns true if a file open for reading has returning a pointer to int
reached the middle.
51.) The operator used for dereferencing or
44.) Which functions allow to change the indirection is .....
location of the get and put positions? A.) *
A.) sg() and sp() B.) &
B.) sekg() and sekp() C.) ->
C.) gog() and gop() D.) ->>
D.) seekg() and seekp()
52.) Choose the right option
45.) Which is correct syntax for position n string* x , Y;
bytes back from end of fileObject? A.) x is a pointer to a string, y is a string
A.) [Link](ios:end,n); B.) y is a pointer to a string, x is a string
B.) [Link](n, ios:end); C.) Both x and y are pointer to string types
C.) [Link](n, ios::end); D.) None of the mentioned
D.) [Link](ios:end,n);
53.) Which one of the following is not a
46.) The first and second arguments of fopen possible state for a pointer?
are A.) Hold the address of the specific object
A.) a character string containing the name of B.) Point one past the end of an object
the file and the second argument is the mode. C.) Zero
B.) a character string containing the name of D.) Point to a type
the user and the second argument is the mode.
C.) a character string containing file pointer 54.) Which of the following is illegal?
and the second argument is the mode. A.) int *ip;
D.) None of the above B.) string s, *sp;
C.) int i; double* dp = &i;
47.) How to get position n bytes forward in D.) int* pi = 0;
fileObject?
A.) [Link] (ios::cur,n); 55.) Only functions of the class can access the
B.) [Link](n,ios:cur); data of the class and they (functions) provide
C.) [Link](n,ios::cur); the interface between data, objects and the
D.) [Link](ios:cur,n); program. This kind of isolation of the data
from direct access by the program is called .....
48.) How to get position to the nth byte of A.) data abstraction
fileObject? B.) data hiding
A.) [Link]('filename',n); C.) data binding
B.) [Link](n,'filename'); D.) data encapsulation
C.) [Link](n);
D.) [Link](n,ios::app); 56.) ..... is the OOP feature and mechanism
that binds together code and the data it
49.) Which of the following fopen statements manipulates, and keep both safe from outside
are illegal? world.
A.) fp = fopen("[Link]","r"); A.) Data binding
B.) fp = fopen("/home/user1/[Link]","w"); B.) Data encapsulation
4
contact@[Link] 9910707562
C++ Assignment S P SHARMA CLASSES [Link]
C.) Data storing 63.) The dot operator connects the following
D.) data abstraction two entities (reading from left to right)
A.) a class member and a class object
57.) The feature in object oriented B.) a class object and a class
programming that allows the same operation C.) a class and a member of that class
to be carried out differently, depending on the D.) a class object and a member of that class
object, is .....
A.) inheritance 64.) .... is a blueprint or prototype that defines
B.) polymorphism the variables and the methods common to all
C.) over functioning objects of a certain kind.
D.) overriding A.) Class
B.) Inheritance
58.) Consider an operation of addition. C.) Object
For two numbers the operation will generate a D.) Polymorphism
sum. If the operands are strings, and the same
operation would produce a third string by 65.) Which of these following members are
concatenation. This feature is called not accessed by using direct member access
A.) inheritance operator?
B.) encapsulation A.) public
C.) polymorphism B.) protected
D.) binding C.) private
D.) Both (B) and (C)
59.) A C++ program contains a function with
the header int function (double d, char c); 66.) Which of the following remarks about the
Which of the following function headers could differences between constructors and
be used within the same program? destructors are correct?
A.) char function (double d, char c) A.) Constructors can take arguments but
B.) int function (int d, char c) destructors cannot.
C.) Both (A) and (B) B.) Constructors can be overloaded but
D.) float function (double d, char c) destructors cannot be overloaded.
C.) Destructors can take arguments but
60.) In C++, we can use the same function constructors cannot.
name to create functions that perform a variety D.) Both (A) and (B)
of different tasks. This is known as
A.) global function 67.) If default constructor is not defined, then
B.) function overloading how the objects of the class will be created?
C.) inheritance A.) The compiler will generate error
D.) All of the above B.) Error will occur at run time
C.) Compiler automatically provides its
61.) The feature that allows you to use the default constructor to build the object
same function name for separate functions that D.) None of the above
have different argument lists is called
A.) overriding 68.) Assume a class TEST. Which of the
B.) overloading following statements is/are responsible to
C.) constructing invoke copy constructor?
D.) destructing A.) TEST T2 (T1)
B.) TEST T4 = T1
62.) What is the term used to describe the C.) T2 = T1
situation when a derived class provides a D.) Both (A) and (B)
function already provided in the base class?
A.) Overloading 69.) When the compiler cannot differentiate
B.) Overriding between two overloaded constructors, they are
C.) Polymorphism called
D.) Encapsulation A.) overloaded
B.) destructed
5
contact@[Link] 9910707562
C++ Assignment S P SHARMA CLASSES [Link]
70.) If you omit any constructor argument 76.) What is difference between protected and
when you instantiate an object, you must use private access specifier in inheritance?
default values A.) private member is not inheritable but
A.) for all parameters to the constructor accessible in derived class
B.) for all parameters to the right of the B.) protected member is inheritable and also
argument accessible in derived class
C.) for all parameters to the left of the C.) Both are inheritable but private is
argument accessible in the derived class
D.) for no other parameters D.) Both are inheritable but protected is not
accessible in the derived class
71.) Assume that we have constructor
functions for both base class and derived class. 77.) In case of inheritance where both base and
Now consider the declaration in main(). derived classes are having constructors, when
Base * P = New Derived; an object of derived class is created then .....
In what sequence will the constructor be A.) constructor of derived class will be
called? invoked first
A.) Derived class constructor followed by base B.) constructor of base class will not be
class constructor invoked
B.) Base class constructor followed by derived C.) constructor of derived class will be
class constructor executed first followed by base class
C.) Base class constructor will not be called D.) constructor of base class will be executed
D.) Base class constructor will not be called first followed by derived class
72.) Which of the following is the invalid class 78.) If base class has constructor with
declaration header for the derived class d with arguments, then it is ..... for the derived class
base classes b1 and b2? to have constructor and pass the arguments to
A.) class d : public b1, public b2 base class constructor.
B.) class d : class b1, class b2 A.) optical
C.) class d : public b1, b2 B.) mandatory
D.) class d : b1, b2 C.) compiler dependent
D.) error
73.) Let class APE be a friend of class
SAPIEN. Let class HUMAN be a child class 79.) When a child class function is called, the
of SAPIEN and let MONKEY be a child class compiler looks first for matching function
of APE. Then name in the .....
A.) SAPIEN is not a friend of APE A.) class of the object using the function name
B.) APE is not a friend of HUMAN B.) immediate ancestor class
C.) MONKEY is not a friend of SAPIEN C.) base class
D.) All of the above D.) descendant class
80.) Assume the C++ definition:
74.) When a child class inherits from more class circle : public point
than one parent class, this type of inheritance Which of the following is false?
is called ..... inheritance. A.) point is the base class and circle is the
A.) hierarchical derived class.
B.) hybrid B.) The colon (:) in the header of class
C.) multilevel definition indicates inheritance.
D.) multiple C.) The keyword 'public' indicates visibility
mode of inheritance
75.) During a class inheritance in C++, if the D.) All the public and protected members of
visibility mode or mode of derivation is not class 'circle' are inherited as public and
provided, then by default visibility mode is ..... protected members respectively, into class
A.) public 'point'.
B.) protected
6
contact@[Link] 9910707562
C++ Assignment S P SHARMA CLASSES [Link]
87.) Which is among following is used to open ii. The capability of a class relay
b. Aggregation
a file for output and move the read/write upon another class.
control to the end of the file?
A.) ios::ate iii. The capability to store one
c. Inheritance
B.) ios::at object inside of another object
7
contact@[Link] 9910707562
C++ Assignment S P SHARMA CLASSES [Link]
96.) Match the following. 99.) When base class is derived in protected
mode, then .....
Table: Execution of base class constructor (i) public members of base class become
private members of derived class
Order of
Method of Inheritance (ii) public members of base class become
Execution
protected members of derived class
I) B(): (iii) public members of base class become
P) class B : public A public members of derived class
C();
(iv) protected members of base class become
8
contact@[Link] 9910707562
C++ Assignment S P SHARMA CLASSES [Link]
{ A.) 5
public: B.) 10
double length,breadth; C.) 15
double height; D.) address of b
};
void main() 109.) What is the output of this program?
{ void main()
Box Box1; {
double volume; char arr[20];
[Link] = 5; int i;
[Link] = 6; for(i=0; i<10; i++)
[Link] = 7.1; *(arr + i) = 65+i;
volume = [Link]* *(arr + i) = '\0';
[Link]*[Link]; cout<<arr;
cout<<volume; }
} A.) ABCDEFGHIJ
A.) 210 B.) AMAAAAAAA
B.) 213 C.) JJJJJJJ
C.) 215 D.) None of the mentioned
D.) 217
107.) What is the output of this program? 110.) What is the output of this program?
class sample void main()
{ {
private: char *ptr;
int var; char Str[] = "abcdefg";
public: ptr = Str;
void input() ptr += 5;
{ cout<<ptr;
cout<<var; }
} A.) fg
void output() B.) defg
{
C.) cdef
cout<<"Variable entered is";
cout<<var<<"\n"; D.) abcd
} Q111 C++ is a
} a) Top down programming approach
void main() b) Procedurally oriented approach
{ c) Bottom-up programming approach
sample object; d) None of these
[Link](); Q112 default return type for all function in
[Link](); c++
[Link](); A) int
} b) float
A.) Enter an integer 5 Variable entered is 5 c) void
B.) runtime error
d) char
C.) error
Q113.c++ developed by whom and when
D.) None of the mentioned
a) Bjarne Stratroup & 1980
b) Dennis Retchie & 1982
108.) What is the output of this program?
void main() c) Bjarne Stratroup & 1982
{ d) None of these
int a = 5, b = 10, c = 15; [Link] is reference variable in c++?
int *arr[] = {&a,&b,&c}; a) To create the alias name of particular
cout<<arr[1]; variable and operator
}; b) To create a pointer
c) To create address
10
contact@[Link] 9910707562
C++ Assignment S P SHARMA CLASSES [Link]