CPP MCQ - 1
CPP MCQ - 1
1) The OOPs concept in C++, exposing only necessary information to users or clients is known
as
A) Abstraction
B) Encapsulation
C) Data hiding
D) Hiding complexity
Answer: A
A) Class
B) Int
C) String
D) Double
Answer: A
A) Abstraction
B) Encapsulation
C) Data hiding
D) Composition
Answer: B
4) For Cat and Animal class, correct way of inheritance is
Answer: A
A) Composition
B) Inheritance
C) Encapsulation
D) None
Answer: A
A) Virtual destructor
B) Virtual constructor
C) Virtual function
D) All
Answer: B
7) IS A relationship in C++ is
A) Inheritance
B) Encapsulation
C) Composition
D) None
Answer: A
8) If you want to write multiple functions in a class with same name, then what C++ feature
will you use?
A) Function overriding
B) Encapsulation
C) Function overloading
D) None
Answer: C
A) Compile time
B) Run time
C) Both
B) None
Answer: C
10) If I want to have common functions in a class and want to defer implementations of some
other functions to derived classes, then we need to use
A) An interface
B) An abstract class
C) A friend class
D) A static class
Answer: B
11) Not using virtual destructor feature in a C++ object oriented programing can cause
A) Memory leak
D) Nothing
Answer: A
A) Encapsulation
B) Inheritance
C) Abstraction
D) None
Answer: B
A) Car obj;
C) Only B
D) A & B both
Answer: D
14) In C++, Class object created statically(e.g. Car obj; and dynamically (Car *obj = new Car() ;
) are stored in memory
A) Stack, heap
B) Heap, heap
C) Heap, stack
D) Stack, stack
Answer: A
D) None
Answer: A
A) Function
B) Operator
C) Object
D) macro
Answer: C
A) Class
B) Int
C) Float
D) array
Answer: A
18) Class allows only one object of it to be created though out the program life cycle
A) Singleton class
B) Abstract class
C) Friend class
D) All classes
Answer: A
B) A obj;
D) None
Answer: B
20) When you create an object of a class A like A obj ; then which one will be called
automatically
A) Constructor
B) Destructor
C) Copy constructor
D) Assignment operator
Answer: A
A) Derived class constructor is called first then the base class constructor
Answer: B
22) The class in C++ which act only as a base class and object of it cannot be created is
A) parent class
B) super class
C) abstract class
Answer: C
23) Data members and member functions of a class in C++ program are by default
A) protected
B) public
C) private
D) None
Answer: C
B) Conditional operator
C) New operator
D) Membership access
Answer: C
A) :
B) ::
C) #
D) None
Answer: B
A) An interface
B) An Abstract class
C) A singleton class
D) A & B
E) A, B & C
Answer: D
A) Constructor
B) Destructor
C) Copy constructor
D) Assignment operator
E) All
Answer: E
A) Inheritance
B) Polymorphism
C) encapsulation
D) None
Answer : A
A) Association
B) Is-A
C) Has-A
D) None
Answer:B
A) Multilevel
B) Multiple
C) Hierarchical
A) Class Re-usability
C) Extendibility
D) All
Answer: D
32) Functions that can be inherited from base class in C++ program
A) Constructor
B) Destructor
C) Static function
D) None
Answer:D
A) Private
B) Protected
C) Public
D) None
Answer:A
B) single inheritance
C) Hybrid inheritance
D) multilevel inheritance
Answer:A
35) In inheritance, order of execution of base class and derived class destructors are
A) Base to derived
B) Derived to base
C) Random order
D) none
Answer: B
A) Operator overloading
B) Function overloading
C) Function overriding
D) B Only
E) A & B
Answer: E
B) Non-virtual function
C) Only pure virtual function
Answer: D
A) Defining multiple functions with same name in a class is called function overloading
D) No statement is false
Answer: C
39) Following keyword is used before a function in a base class to be overridden in derived
class in C++
A) override
B) virtual
C) void
D) none
Answer: B
A) Increment operator
B) Constructor
C) Destructor
D) void func() = 0;
Answer: B
A) To create an interface
Answer: D
A) Constructor
B) Destructor
C) Both A & B
D) Only B
Answer: C
44) How many VPTR is created internally for a base class and a derived class
A) 0
B) 1
C) 2
D) 3
Answer: B
45) Number of virtual table created for a base and a derived class is
A) 0
B) 1
C) 2
D) 3
Answer: C
Answer: B
Answer: D
C) :: operator overloading
D) None
Answer: D
A) Function overriding
B) Operator overloading
C) A & B
D) None
Answer: A
A) Constructor
B) Class destructor
C) Both a & b
D) None
Answer: B
51) Operators can be overloaded in C++ is/are
A) New
B) Delete
C) ++
Answer: D
A) Pass by value
B) Pass by reference
C) Pass by pointer
Answer: D
A) void display()
Answer: B
54) Which of the following functions are provided by compiler by default if we don’t write in
a C++ class?
A) Copy constructor
B) Assignment
C) Constructor
Answer: D
55) Which function can be called without using an object of a class in C++
A) Static function
B) Inline function
C) Friend function
D) constant function
Answer: A
class A{
public:
void func1(){
void func2();
};
Answer: C
57) Which function can be called without using an object of a class in C++
A) Virtual function
B) Inline function
C) Static function
D) constant function
Answer: C
58) Which of the following function declaration using default arguments is correct?
Answer: A
A) Virtual function
B) member function
C) Static function
Answer: C
60) Choose the correct answer for following piece of C++ pseudo code
int main(){
int a,b;
func(a,b);
Answer: A