OOP Semester Final 1
OOP Semester Final 1
ID: 0622220105101004
Topic: Inheritance
a) inherit
b) class
c) extends
d) inherits
e) friend
Answer: b) class
e) A class can inherit from a base class, which in turn inherits from another base class
Answer: e) A class can inherit from a base class, which in turn inherits from another base class
a) Single
b) Multiple
c) Hybrid
d) Multi-dimensional
e) Hierarchical Inheritance.
Answer: d) Multi-dimensional
10. In single inheritance, how many base classes can a derived class have?
a) One
b) Two
c) Three
d) Multiple
e) Unlimited
Answer: a) One
11. In multiple inheritance, how many base classes can a derived class have?
a) One
b) Two
c) Three
d) Multiple
e) Unlimited
Answer: d) Multiple
12. In multi-level inheritance, how many levels can there be between the base class and the derived
class?
a) One
b) Two
c) Three
d) Multiple
e) Unlimited
Answer: e) Unlimited
a. private derivation
b. public derivation
c. protected derivation
a. 6
b.4
c.3
d.5
e.7
ans: d. 5
a) Single inheritance
b) Multilevel inheritance
c) Multiple inheritance
d) Hierarchical inheritance
e) Hybrid inheritance
Ans. d. Hierarchical inheritance.
Ibrahim Hossain
Topic: Abstract Class
Answer: a
a) virtual function
b) pure virtual function
c) derived class
d) base class
e) friend class
Answer: b
Answer: a
Answer: b
Answer: c
#include <iostream>
#include <string>
using namespace std;
class A
{
int a;
public:
virtual void func() = 0;
};
class B: public A
{
public:
void func(){
cout<<"Class B"<<endl;
}
};
a) Class A
b) Class B
c) Segmentation fault
d) No output
e) Error
Answer: b
#include <iostream>
#include <string>
using namespace std;
class A
{
int a;
public:
virtual void func() = 0;
};
class B: public A
{
public:
void func(){
cout<<"Class B"<<endl;
}
};
a) Class A
b) Class B
c) Segmentation fault
d) No output
e) Error
Answer: e
• Friend Functions
b) A function which can’t access all the private, protected and public members of a class
c) A function which is not allowed to access any member of any class
d) A function which is allowed to access public and protected members of a class
e) A function which is allowed to access only public members of a class
Answer: a
Answer: a
10. Which of the following is correct about friend functions?
a) Friend functions can access only protected members not the private members
Answer: e
Answer: c
Answer: e
Answer: a
#include <iostream>
#include <string>
using namespace std;
class Box
{
int capacity;
public:
Box(int cap)
{
capacity = cap;
}
void show()
{
Box b(10);
cout<<"Value of capacity is: "<<b.capacity<<endl;
}
Answer: a
Nazmul Hassan
Topic : Friend Functiom
1.Which keyword is used to represent a friend function?
A. friend
B. Friend
C. friend_func
D. Friend_func
Ans: A
A. function declaration
B. function definition
C. main function
D. block function
Ans:A
D. Friend functions can access only protected members not the private members
Ans: C
Ans:B
A. Static function
B. Inline function
C. Friend function
D. constant function
Ans:A
e) Relevant option:
a) Inheritance.
b) Aggregation.
c) Association.
d) Composition.
e) Relevant option:
Ans:c) Association
a) public.
b) private.
c) protected.
e) Relevant option:
a) Friend functions are only visible within the class they are declared in.
b) Friend functions are only visible within the file they are defined in.
c) Friend functions are only visible within the namespace they are declared in.
e) Relevant option:
Ans:b) Friend functions are only visible within the file they are defined in.
10.How many member functions are there in this C++ class excluding constructors and
destructors?
class Box
int capacity;
public:
void print();
bool compare();
};
a) 1
b) 2
c) 3
d) 4
ans:b
#include <iostream>
#include <string>
class B
int b;
public:
B(){}
B(int i){
b = i;
}
int show(){
return b;
};
class C
B b;
public:
C(int i){
b = B(i);
C c(10);
};
show();
return 0;
a) value of b is: 10
c) error
d) segmentation fault
Ans:C
b) friend class;
c) friend class
d) friend class()
Ans:A
13.Global Function can be Friend functions for which of the following class?
Ans:C
#include <iostream>
class one {
private:
int n1=1;
public:
};
int main()
one object1
return 0;
}}
(A). class
(B). arguments
(c). child
(D). Parent
Ans:B
15.
Name : Anika Bushra
ID : 0622220205101015
Topic:
1. C++ supports run time polymorphism with the help of virtual functions, which is called ……………..
binding.
A) dynamic
B) run time
C) early binding
D)static
E) compile time binding
Ans: A
2. Run time polymorphism is achieved only when a ……………….. is accessed through a pointer to the base
class.
A) member function
B) virtual function
C) static function
D) real function
E) dynamic function
Ans: B
Ans:D
5. Which 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
e)It is the inability for many messages to be processed in one way
Ans: A
11. The languages that support classes but not polymorphism is called?
A. child Class-based language
B. Class-based language
C. Object-based language
D. object class based language
E. Procedure Oriented language
Ans: C
A) Heritance
B) Poly programming
C) Encapsulation
D) Overloading
E) Virtual function
Ans : D
13. The mechanism of giving special meaning to an operator is called ____
A) Object
B) Inheritance
C ) Ambiguity
D) Operator Overloading
E) Function overloading
Ans : D
14. When a virtual function is redefined by the derived class, it is called__________
a. Overloading
b. Overriding
c. Rewriting
d. polymorphism
e. inheritance
Ans : b
a) Function overloading
b) Early binding
c) Late binding
d) Function hiding
e) Static binding
class?
a) new
b) override
c) extend
d) inherit
e) virtual
Answer: b) override
keyword:
a) base
b) virtual
c) override
d) derived
e) polymorphic
Answer: b) virtual
c) The derived class function has the same name as the base class
function.
function.
5. Which keyword is used to prevent further overriding of a virtual
a) restrict
b) override
c) final
d) prevent
e) lock
Answer: c) final
classes.
a) Must have the same return type as the base class function.
c) Must have the same access specifier as the base class function.
d) Must have the same number of parameters as the base class
function.
e) Must have a different return type than the base class function.
Answer: a) Must have the same return type as the base class
function.
11. A class that contains at least one pure virtual function is called
a/an:
a) Concrete class
b) Derived class
c) Abstract class
d) Final class
e) Static class
Answer: c) Abstract class
a) Overloading
b) Overriding
c) Polymorphism
d) Inheritance
e) Encapsulation
Answer: b) Overriding
function declaration?
classes.
derived classes.
Topic: object oriented I/o.
Meherun Kajol
A. ostream class.
B. instream class.
c. istream class.
D. bufstream class.
E.imstream class.
Answer: B
1. A class that defined the cout , cerr , and clog objects and stream insertion operator is called…
A. Istream.
B. Ostream.
C. Fstream.
D. Kstream.
E. Bufstream.
Answer; B
3.The I/o operations that use the extraction and insertion operations, are called…
A. Formatted I/o.
B. Formatted strings.
c. Formatted flogs.
d. Formatted o/I
E. all of them.
Answer: A
2. Pick out the currect objects about the instantiation of output stream..
A. Cout
B. Cerr
C. Clog
D. Cin
E. A to c
Answer: E
A. 1
B. 2
c. 3
D. 4
Answer: B
A. cout
B. cin
c. coi
D. cinout
E. clog
Answer: B
A. >
B. >>
C. <
D. <<
E. >^
Answer: B
8. if we have object from ofstream class , then default mode of opening the file is
A. ios:: ate
B. ios:: nocreate
c. ios:: noreplace
D. ios:: truncate
E. ios:: create
Answer: D
A. of stream
B. ifstream
C. iostream
D. offstream
E. Fstream
Answer: A
A. <iostream>
B. <ofstream>
C. <fstream>
D. <instream>
E. < offstream>
Answer: A
11. how many objects are used for input and output to a string?
A. 1
B.2
C. 3
D.4
E. 5
Answer: C
12. which from the following functions doesnot extract the delimiter character from the input stream.
A. get()
B. getline()
C. get char()
D. get string()
E. get float()
Answer: A
13. which function is used to position back from the end of file object?
A. seekg
B. seekp
c. seekf
D. seekg&seekp
E. seekm
Answer: A
Include<iostream>
Int main 0
Int I;
return 0;
A. 73
B. Your value +4
C. Error
D. 63
E. 34
Answer: C
A. cin objects
C. cout object
D. A and B
E. c in out objects
Answer: D
Samiya Islam
a)Set of C++ template classes to provide common programming data structures & functions.
e)
Answer:a
a) 1
b) 2
c) 3
d) 4
e)5
Answer: d
e)
Answer: c
a) <iterator>
b) <algorithm>
c) <iter>
d) <loopItere>
e)<iostream>
Answer: a
a) 2
b) 3
c) 4
d) 5
e) 6
Answer: d
e)
Answer: a
Answer: c
c) Iterator that can only be used to access the sequence from both sides
d) Iterator that can only be used to assign the sequence from both sides
Answer: b
Answer: a
10. Which of the following header file is needed to use vectors in your program?
a) <array>
b) <vector>
c) <containers>
d) <stdio>
e)<iostream>
Answer: b
11. Which of the following(s) can be used to access the first element of a vector v?
a) v.begin[0]
b) v.cbegin[ ]
c) v( )
d) v.at(0)
e) v.begin[ ]
Answer:d
12. Which of the following(s) can be used to access the last element of a vector v?
a) v.end()
b) v.cend()
e) V.END[ ]
Answer: d
Answer: c
14. Which of the following function is used to get the actual number of elements
stored in vector?
a) v.size()
b) v.capacity()
c) v.max_size()
d) v.no_of_elements()
e) v.capacity [1]
Answer: a
Answer: b
Neyamul Islam
ID 0922220105101005
B. A separate process
C. A lightweight process
D. A subroutine
E. An input/output operation
C. Easier debugging
D. Higher portability
E. Higher security
Answer: B. A section of code that must be executed by only one thread at a time
A. Synchronization
B. Preemption
C. Deadlock
D. Segmentation
E. Garbage collection
Answer: A. Synchronization
A. A function that can be executed by multiple threads simultaneously without causing race conditions
Answer: A. A function that can be executed by multiple threads simultaneously without causing race
conditions
A. A situation where two or more threads are waiting for each other to release a resource
B. A situation where two or more threads are executing the same critical section
Answer: A. A situation where two or more threads are waiting for each other to release a resource
A. Using synchronization
B. Using preemption
C. Using segmentation
E. Using timeouts
A. stdio.h
B. math.h
C. pthread.h
D. stdlib.h
E. time.h
Answer: C. pthread.h
Answer: A. A data structure used to synchronize threads
B. A lightweight process that shares memory and resources with other threads
Answer: B. A lightweight process that shares memory and resources with other threads
C. Enhanced modularity
12. Which of the following is NOT a synchronization mechanism used in multi-thread programming?
A. Semaphores
B. Monitors
C. Locks
D. Mutexes
E. Context switches
A. A condition in which two or more threads try to access a shared resource simultaneously
Answer: A. A condition in which two or more threads try to access a shared resource simultaneously
A. A condition in which two or more threads try to access a shared resource simultaneously
B. A technique that creates a fixed number of threads and reuses them to execute tasks
Answer: B. A technique that creates a fixed number of threads and reuses them to execute tasks
a) A function that can be used to create multiple functions with the same code
Answer: a) A function that can be used to create multiple functions with the same code
a) Yes
b) No
Answer: a) Yes
a) int
b) float
c) char
d) const int
8. Can a template function have both type and non-type template parameters?
a) Yes
b) No
Answer: a) Yes
a) To allow for the creation of a template function with specific template parameters
d) To allow for the creation of a template function with a non-type template parameter
b) To create a specialized version of a template function for a specific non-type template parameter
Answer: c) To create a specialized version of a template function for a specific combination of template
parameters
12. What is the default access specifier for members of a class in C++?
a) Public
b) Private
c) Protected
d) Static
b) The process of hiding the implementation details of a class from the outside world
Answer: b) The process of hiding the implementation details of a class from the outside world
b) A constructor is called when an object is destroyed, while a destructor is called when an object is
created
c) A constructor is used to allocate memory for an object, while a destructor is used to deallocate
memory for an object
Answer: d) A constructor is called automatically when an object is created, while a destructor is called
automatically when an object is destroyed
15. What is the difference between a member function and a static member function in a C++ class?
a) A member function is called on an object, while a static member function is called on the class itself
b) A member function can access only public members of a class, while a static member function can
access all members of a class
c) A member function is declared with the static keyword, while a static member function is declared
without the static keyword
d) A member function can be called from outside the class, while a static member function can be called
only from within the class
Answer: a) A member function is called on an object, while a static member function is called on the
class itself