Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

Object Oriented Programming Using C++

Unit 4 : Pointers and Polymorphism


----------------------------------
Concept of Pointer

m
Pointer to object
Introduction to Polymorphism

Te a
ir
Types of Polymorphism
Compile Time Polymorphism - Static Binding
Function Overloading
ib S
Operator Overloading
s h
To
Run Time Polymorphism - Dynamic Binding - FUnction Override
Virtual Function

Unit 5 : File Operations


------------------------
C++ Stream Classes
Operations on file - Opening, Closing, Read, Write
File End & File Modes
• Which among the following best describes polymorphism?
a) It is the ability for a message/data to be processed in more than one form - correct
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

• Which is the correct statement anout operator overloading in C++?.


A. Only arithmetic operators can be overloaded
B. Associativity and precedence of operators does not change - correct
C. Precedence of operators are changed after overlaoding
a m
D. Only non-arithmetic operators can be overloaded

ir Te
• Which of the following operators cannot be overloaded?
ib S
A. .* (Pointer-to-member Operator )
s h
To
B. :: (Scope Resolution Operator)
C. .* (Pointer-to-member Operator )
D. All of the above – correct

• Select operators which can be overloaded?


+
-
=
All of the above

• For polymorphism, function must be property of object, not only of class?


TRUE
FALSE
• Which of the following options correctly explains the concept of Polymorphism?
a. int func(float);
float func(int, int, char); --- correct

b. int func(int);
int func(int);

c. int func(int, int);


float func1(float, float);
a m
d. None of the above
ir Te
ib S

h
Which is correct syntax for declaring pointer to object?
s
To
a) className* objectName; - correct
b) className objectName;
c) *className objectName;
d) className objectName();

• Which operator should be used to access the members of the class using object pointer?
a) Dot operator
b) Colon to the member
c) Scope resolution operator
d) Arrow operator -- correct
• A pointer _________________
a) Can point to only one object at a time - correct
b) Can point to more than one objects at a time
c) Can point to only 2 objects at a time
d) Can point to whole class objects at a time

• Pointer to a base class can be initialized with the address of derived class, because of _________
a) derived-to-base implicit conversion for pointers - correct
b) base-to-derived implicit conversion for pointers
a m
Te
c) base-to-base implicit conversion for pointers

ir
d) derived-to-derived implicit conversion for pointers


ib
Can pointers to object access the private members of the class? S
a) Yes, always
s h
b) Yes, only if it is only pointer to object
To
c) No, because objects can be referenced from another objects too
d) No, never – correct

• Which among the following is true?


a) The pointer to object can hold address only - correct
b) The pointer can hold value of any type
c) The pointer can hold only void reference
d) The pointer can’t hold any value
• Which is the correct syntax to call a member function using pointer?
a) pointer->function() - correct
b) pointer.function()
c) pointer::function()
d) pointer:function()

• Which type of function shows polymorphism among the following?


A. Inline function
B. Virtual function - correct
a m
Te
C. Undefined functions
D. Class member functions
Sir
• Which one of the following can show polymorphism?
s h ib
To
A. Overloading ||
B. Overloading &&
C. Overloading << - correct
D.Overloading +=

• Run time polymorphism is achieved only when a ……………….. Is accessed through a pointer to the base class.
A) static function
B) Real function
C. Member function
D) Virtual function - correct
• Compile time polymorphism in C++ language are
Operator overloading
Function overloading
Function overriding
B Only
A & B – correct

• False statements about function overloading is

a m
Defining multiple functions with same name in a class is called function overloading
Overloaded function must differ in their order and types of arguments.

ir
Overloaded functions should be preceded with virtual keyword - correct Te
No statement is false
ib S
s h
To
• Following keyword is used before a function in a base class to be overridden in derived class in C++
override
virtual - correct
void
none

• Which is the correct declaration of pure virtual function in C++


virtual void func = 0;
virtual void func() = 0; - correct
virtual void func(){0};
void func() = 0;
• Which statements are true about an abstract class
Abstract class has at least one pure virtual function.
Pointer for an abstract class can be created
Object of an abstract class cannot be created.
All are correct. – correct

• Run time polymorphism in C++ Program is


New and delete operator overloading
++ and – – operator overloading
a m
Te
:: operator overloading
None – correct
Sir
• Run time binding is related to
s h ib
To
Function overriding - correct
Operator overloading
A&B
None

• Which function cannot be overloaded in C++


Constructor
Destructor - correct
Both a & b
None
• To read and write from a file we are using the standard C++ library called ______?
fstream - correct
ifstream
ofstream
none of the above

• Which header file is required to use file I/O operations?


a) <ifstream>
b) <ostream>
c) <fstream> - correct
a m
Te
d) <iostream>

• Which of the following is used to create an output stream?


Sir
a) ofstream - correct (read file)
b) ifstream
s h ib
To
c) iostream
d) fsstream

• Which of the following is not used as a file opening mode?


a) ios::trunc - correct
b) ios::binary
c) ios::in
d) ios::ate

• By default, all the files in C++ are opened in _________ mode.


a) Text - correct
b) Binary
c) ISCII
d) VTC
• Which of the following is the default mode of the opening using the ofstream class?
a) ios::in
b) ios::out - correct
c) ios::app
d) ios::trunc

• What is the return type open() method?


a) int
b) char
a m
Te
c) bool - correct

ir
d) float


ib S
h
Which of the following is the default mode of the opening using the ifstream class?
a) ios::in - correct
b) ios::out
To s
c) ios::app
d) ios::trunc

• Which of the following is the default mode of the opening using the fstream class?
a) ios::in
b) ios::out
c) ios::in|ios::out - correct
d) ios::trunc
• Which of the following is used to move the file pointer to start of a file?
a) ios::beg - correct
b) ios::start
c) ios::cur
d) ios::first

• Which function is used in C++ to get the current position of file pointer in a file?
a) tell_p() - correct
b) get_pos()
a m
c) get_p()
d) tell_pos()
ir Te
 
ib S
s h
To

You might also like