Object Oriented Programming Set 4
On This Page
This set of Object Oriented Programming OOP Multiple Choice Questions & Answers (MCQs) focuses on Object Oriented Programming Set 4
Q1 | C++ was originally developed by ….......
- donald knuth
- bjarne sroustrups
- dennis ritchie
- none of these
Q2 | Which of the following approach is adopted in C++?
- top down
- bottom up
- horizontal
- vertical
Q3 | Which feature of C++ contain the concept of super class and subclass?
- class and object
- encapsulation
- abstraction
- inheritance
Q4 | The main intention of using inheritance is ….........
- to help in converting one data type to other
- to hide the details of base class
- to extend the capabilities of base class
- to help in modular programming
Q5 | If particular software can be used in some other application than the one for which it is created then it reveals ….........
- data binding
- data reusability
- data encapsulation
- none of these
Q6 | Which of the following data type does not return anything?
- int
- short
- long
- void
Q7 | How many objects can be created from an abstract class?
- zero
- one
- two
- as many as we want
Q8 | Which of the following statements is correct for a static member function?1. It can access only other static members of its class. It can be called using the class name, instead of objects
- only 1 is correct
- only 2 is correct
- both 1 and 2 are correct
- both 1 and 2 are incorrect
Q9 | What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero-argument constructor?
- compile-time error
- preprocessing error
- runtime error
- runtime exception
Q10 | Which of the following interface determines how your program will be used by other program?
- public
- private
- protected
- none of these
Q11 | What is the difference between struct and class in C++?
- all members of a structure are public and structures don't have constructors and destructors
- members of a class are private by default and members of struct are public by default. when deriving a struct from a class/struct, default access-specifier for a base class/struct is public and when deriving a class, default access specifier is private.
- all members of a structure are public and structures don't have virtual functions
- all above
Q12 | Predict the output of following C++ program#include using namespace std;class Empty {}; int main(){cout <
- a non zero value
- 0
- compile time error
- runtime error
Q13 | class Test { int x;};int main(){Test t; cout <
- 0
- garbage value
- compile time error
Q14 | Which of the following is true?
- all objects of a class share all data members of class
- objects of a class do not share non-static members. every object has its own copy
- objects of a class do not share codes of non-static methods, they have their own copy
- none
Q15 | Which of the following is true about the following program#include class Test{public:int i;void get();};void Test::get(){std::cout <<"Enter the value of i: "; std::cin >>i;}Test t; // Global object int main(){Test t; // local object t.get();std::cout <<"value of i in local t: "<
- compiler error: cannot have two objects with same class name
- compiler error in line "::t.get();
- compiles and runs fine
Q16 | Which of the following is true about new when compared with malloc. 1) new is an operator, malloc is a function 2) new calls constructor, malloc doesn't 3) new returns appropriate pointer, malloc returns void * and pointer needs to typecast to appropriate type.
- 1 and 3
- 2 and 3
- 1 and 2
- all 1,2,3
Q17 | Predict the output?#include using namespace std;class Test{int x;Test() { x = 5;}};int main(){Test *t = new Test; cout <x;}
- compile time error
- garbage
- 5
Q18 | What happens when delete is used for a NULL pointer? int *ptr = NULL;delete ptr;
- compile time error
- run time error
- no effect
Q19 | Is it fine to call delete twice for a pointer?#include using namespace std;int main(){int *ptr = new int; delete ptr;delete ptr; return 0;}
- yes
- no
Q20 | Which of the followings is/are automatically added to every class, if we do not write our own.
- copy constructor
- assignment operator
- a constructor without any parameter
- all
Q21 | When a copy constructor may be called?
- when an object of the class is returned by value
- when an object of the class is passed (to a function) by value as an argument
- when an object is constructed based on another object of the same class
- all
Q22 | Output of following program?#include using namespace std; class Point {Point() { cout <<"Constructor called"; }};int main(){Point t1; return 0;}
- compile time error
- run time error
- constructor called
Q23 | #include using namespace std; class Point {public:Point() { cout <<"Constructor called"; }};int main(){Point t1, *t2; return 0;}
- compiler error
- constructor called constructor called
- constructor called
Q24 | #include using namespace std;class X{public:int x;};int main(){X a = {10};X b = a;cout <
- compiler error
- 10 followed by garbage value
- 10 10
- 10 0