Object Oriented Programming Oop Set 4

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Object Oriented Programming (OOP) MCQs

[set-4]

76. C++ was originally developed by ….......


A. donald knuth
B. bjarne sroustrups
C. dennis ritchie
D. none of these
Answer: B

77. Which of the following approach is adopted in C++?


A. top down
o m
B. bottom up
. c
C. horizontal
te
D. vertical
a
Answer: B

q M
c the concept of super class and subclass?
78. Which feature of C++ contain
A. class and object M
B. encapsulation
C. abstraction
D. inheritance
Answer: D

79. The main intention of using inheritance is ….........


A. to help in converting one data type to other
B. to hide the details of base class
C. to extend the capabilities of base class
D. to help in modular programming
Answer: C

80. If particular software can be used in some other application than the one for
which it is created then it reveals ….........
A. data binding
B. data reusability
C. data encapsulation
D. none of these
Answer: B

81. Which of the following data type does not return anything?
A. int
B. short
C. long
D. void
Answer: D

82. How many objects can be created from an abstract class?


A. zero
B. one
C. two
D. as many as we want
Answer: A

83. 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
A. only 1 is correct
B. only 2 is correct
C. both 1 and 2 are correct
D. both 1 and 2 are incorrect
Answer: C

84. 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?
A. compile-time error
B. preprocessing error
C. runtime error
D. runtime exception
Answer: A

View all MCQ's at McqMate.com


85. Which of the following interface determines how your program will be used by
other program?
A. public
B. private
C. protected
D. none of these
Answer: A

86. What is the difference between struct and class in C++?


A. all members of a structure are public and structures don't have constructors and destructors
B. 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.
C. all members of a structure are public and structures don't have virtual functions
D. all above
Answer: B

87. Predict the output of following C++ program


#include<iostream> using namespace std;
class Empty {}; int main()
{
cout <<sizeof(Empty); return 0;
}
A. a non zero value
B. 0
C. compile time error
D. runtime error
Answer: A

88. class Test { int x;


};
int main()
{
Test t; cout <<t.x; return 0;
}
A. 0
B. garbage value

View all MCQ's at McqMate.com


C. compile time error
Answer: C

89. Which of the following is true?


A. all objects of a class share all data members of class
B. objects of a class do not share non-static members. every object has its own copy
C. objects of a class do not share codes of non-static methods, they have their own copy
D. none
Answer: B

90. Which of the following is true about the following program


#include <iostream> 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: "<<t.i<<'\n';
::t.get();
std::cout <<"value of i in global t: "<<::t.i<<'\n'; return 0;
}
A. compiler error: cannot have two objects with same class name
B. compiler error in line "::t.get();"
C. compiles and runs fine
Answer: C

91. 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.

View all MCQ's at McqMate.com


A. 1 and 3
B. 2 and 3
C. 1 and 2
D. all 1,2,3
Answer: C

92. Predict the output?


#include <iostream> using namespace std;
class Test
{
int x;
Test() { x = 5;}
};
int main()
{
Test *t = new Test; cout <<t->x;
}
A. compile time error
B. garbage
C. 0
D. 5
Answer: A

93. What happens when delete is used for a NULL pointer? int *ptr = NULL;
delete ptr;
A. compile time error
B. run time error
C. no effect
Answer: C

94. Is it fine to call delete twice for a pointer?


#include<iostream> using namespace std;
int main()
{
int *ptr = new int; delete ptr;
delete ptr; return 0;
}

View all MCQ's at McqMate.com


A. yes
B. no
Answer: B

95. Which of the followings is/are automatically added to every class, if we do not
write our own.
A. copy constructor
B. assignment operator
C. a constructor without any parameter
D. all
Answer: D

96. When a copy constructor may be called?


A. when an object of the class is returned by value
B. when an object of the class is passed (to a function) by value as an argument
C. when an object is constructed based on another object of the same class
D. all
Answer: D

97. Output of following program?


#include<iostream> using namespace std; class Point {
Point() { cout <<"Constructor called"; }
};
int main()
{
Point t1; return 0;
}
A. compile time error
B. run time error
C. constructor called
Answer: A

98. #include<iostream> using namespace std; class Point {


public:
Point() { cout <<"Constructor called"; }
};
int main()

View all MCQ's at McqMate.com


{
Point t1, *t2; return 0;
}
A. compiler error
B. constructor called constructor called
C. constructor called
Answer: C

99. #include<iostream> using namespace std;


class X
{
public:
int x;
};
int main()
{
X a = {10};
X b = a;
cout <<a.x <<" " <<b.x; return 0;
}
A. compiler error
B. 10 followed by garbage value
C. 10 10
D. 10 0
Answer: D

View all MCQ's at McqMate.com

You might also like