OOPs MCQ (Multiple Choice Questions) - Sanfoundry
OOPs MCQ (Multiple Choice Questions) - Sanfoundry
OOPs MCQ (Multiple Choice Questions) - Sanfoundry
Programming MCQ
(Multiple Choice Questions)
Here are 1000 MCQs on Object Oriented Programming
(Chapterwise).
View Answer
Answer: c
Explanation: Alan Kay invented OOP, Andrea Ferro was
a part of SmallTalk Development. Dennis invented C++
and Adele Goldberg was in team to develop SmallTalk
but Alan actually had got rewarded for OOP.
View Answer
Answer: d
Explanation: Duplicate/Redundant data is dependent on
programmer and hence can’t be guaranteed by OOP.
Code reusability is done using inheritance. Modularity is
supported by using di"erent code files and classes.
Codes are more e!cient because of features of OOP.
View Answer
Answer: b
Explanation: SmallTalk was the first programming
language developed which was purely object oriented.
It was developed by Alan Kay. OOP concept came into
the picture in 1970’s.
View Answer
Answer: c
Explanation: OOP first came into picture in 1970’s by
Alan and his team. Later it was used by some
programming languages and got implemented
successfully, SmallTalk was first language to use pure
OOP and followed all rules strictly.
View Answer
Answer: d
Explanation: Inheritance indicates the code reusability.
Encapsulation and abstraction are meant to hide/group
data into one element. Polymorphism is to indicate
di"erent tasks performed by a single entity.
advertisement
View Answer
Answer: a
Explanation: We need not include any specific header
file to use OOP concept in C++, only specific functions
used in code need their respective header files to be
included or classes should be defined if needed.
View Answer
Answer: b
Explanation: As Java supports usual declaration of data
variables, it is partial implementation of OOP. Because
according to rules of OOP, object constructors must be
used, even for declaration of variables.
View Answer
Answer: c
Explanation: Platform independence is not feature of
OOP. C++ supports OOP but it’s not a platform
independent language. Platform independence
depends on the programming language.
View Answer
Answer: b
Explanation: Firstly, keyword class should come,
followed by the derived class name. Colon is must
followed by access in which base class has to be
derived, followed by the base class name. And finally
the body of class. Semicolon after the body is also must.
View Answer
Answer: a
Explanation: Encapsulation is indicated by use of
classes. Inheritance is shown by inheriting the student
class into topper class. Polymorphism is not shown here
because we have defined the constructor in the topper
class but that doesn’t mean that default constructor is
overloaded.
View Answer
Answer: b
Explanation: The interaction between two object is
called the message passing feature. Data transfer is not
a feature of OOP. Also, message reading is not a feature
of OOP.
View Answer
Answer: c
Explanation: The language must follow all the rules of
OOP to be called a purely OOP language. Even if a single
OOP feature is not followed, then it’s known to be a
partially OOP language.
advertisement
View Answer
Answer: b
Explanation: Only 3 types of access specifiers are
available. Namely, private, protected and public. All
these three can be used according to the need of
security of members.
View Answer
Answer: d
Explanation: The classes using multilevel inheritance
will use the code in all the subsequent subclasses if
available. Hence the most significant feature among the
options given is code reusability. This feature is
generally intended to use the data values and reuse the
redundant functions.
View Answer
Answer: a
Explanation: It is a way of combining both data
members and member functions, which operate on
those data members, into a single unit. We call it a class
in OOP generally. This feature have helped us modify
the structures used in C language to be upgraded into
class in C++ and other languages.
View Answer
Answer: b
Explanation: It never increases function definition
overhead, one way or another if you don’t use
polymorphism, you will use the definition in some other
way, so it actually helps to write e!cient codes.
advertisement
class A
{
int i;
A()
{
i=0; cout<<i;
}
A(int x=0)
{
i=x; cout<<I;
}
};
A obj1;
a) Parameterized constructor
b) Default constructor
c) Run time error
d) Compile time error
View Answer
Answer: d
Explanation: When a default constructor is defined and
another constructor with 1 default value argument is
defined, creating object without parameter will create
ambiguity for the compiler. The compiler won’t be able
to decide which constructor should be called, hence
compile time error.
View Answer
Answer: a
Explanation: It includes hiding the implementation part
and showing only the required data and features to the
user. It is done to hide the implementation complexity
and details from the user. And to provide a good
interface in programming.
View Answer
Answer: b
Explanation: Only insertion operator can be overloaded
among all the given options. And the polymorphism can
be illustrated here only if any of these is applicable of
being overloaded. Overloading is type of polymorphism.
View Answer
Answer: c
Explanation: Constructor function should be available to
all the parts of program where the object is to be
created. Hence it is advised to define it in public access,
so that any other function is able to create objects.
class student
{
int marks;
public: student(){}
student(int x)
{
marks=x;
}
};
main()
{
student s1(100);
student s2();
student s3=100;
return 0;
}
View Answer
Answer: d
Explanation: It is a special case of constructor with only
1 argument. While calling a constructor with one
argument, you are actually implicitly creating a
conversion from the argument type to the type of class.
Hence you can directly specify the value of that one
argument with assignment operator.
View Answer
Answer: c
Explanation: When an object is passed to a function,
actually its copy is made in the function. To copy the
values, copy constructor is used. Hence the object being
passed and object being used in function are di"erent.
class A
{
int i;
A()
{
i=0;
}
A(int x)
{
i=x+1;
}
A(int y, int x)
{
i=x+y;
}
};
A obj1(10);
A obj2(10,20);
A obj3;
a) A(int y, int x)
b) A(int y; int x)
c) A(int y)
d) A(int x)
View Answer
Answer: a
Explanation: The two argument constructor will be
called as we are passing 2 arguments to the object
while creation. The arguments will be passed together
and hence compiler resolves that two argument
constructor have to be called.
View Answer
Answer: b
Explanation: The constructors must contain only the
class name. The class name is followed by the blank
parenthesis or we can have parameters if some values
are to be passed.
View Answer
Answer: c
Explanation: The destructor is never called in this
situation. The concept is that when an object is passed
by reference to the function, the constructor is not
called, but only the main object will be used. Hence no
destructor will be called at end of function.
View Answer
Answer: b
Explanation: All the data members should be made
private to ensure the highest security of data. In special
cases we can use public or protected access, but it is
advised to keep the data members private always.
View Answer
Answer: d
Explanation: The data members can never be called
directly. Dot operator is used to access the members
with help of object of class. Arrow is usually used if
pointers are used.
View Answer
Answer: a
Explanation: Using inheritance we can have the security
of the class being inherited. The subclass can access the
members of parent class. And have more feature than a
nested class being used.
View Answer
Answer: c
Explanation: The keyword new can be used to declare
an array of objects in java. The syntax must be specified
with an object pointer which is assigned with a memory
space containing the required number of object space.
Even initialization can be done directly.
View Answer
Answer: d
Explanation: The delete operator in C++ can be used to
free the memory and resources held by an object. The
function can be called explicitly whenever required. In
C++ memory management must be done by the
programmer. There is no automatic memory
management in C++.
View Answer
Answer: b
Explanation: The names are not property of an object.
The identity can be in any form like address or name of
object but name can’t be termed as only identity of an
object. The objects contain attributes that define what
type of data an object can store.
View Answer
Answer: c
Explanation: The private members can be accessed only
inside the base class. If the class is derived by other
classes. Those members will not be accessible. This
concept of OOP is made to make the members more
secure.
View Answer
Answer: a
Explanation: It can only be indicated by using the data
and functions that we use in derived class, being
provided by parent class. Copying code is nowhere
similar to this concept, also using the code already
written is same as copying. Using already defined
functions is not inheritance as we are not adding any of
our own features.
View Answer
Answer: d