Sie sind auf Seite 1von 6

1. Which is known as generic class?

a) Abstract class
b) Final class
c) Template class
d) Efficient Code
Answer: c

2. Which of the following describes a friend class?


a) Friend class can access all the private members of the class, of which it is a friend
b) Friend class can only access protected members of the class, of which it is a friend
c) Friend class don’t have any implementation
d) Friend class can’t access any data member of another class but can use it’s methods
Answer: a
Explanation: A friend class can access all the private members of another class, of which
it is friend. It is a special class provided to use when you need to reuse the data of a
class but don’t want that class to have those special functions.

3. Which among the following is false, for member function of a class?


a) All member functions must be defined
b) Member functions can be defined inside or outside the class body
c) Member functions need not be declared inside the class definition
d) Member functions can be made friend to another class using friend keyword
Answer: c
Explanation: Member functions must be declared inside class body, thought the definition
can be given outside the class body. There is no way to declare the member functions
inside the class.

4. Which of the following pairs are similar?


a) Class and object
b) Class and structure
c) Structure and object
d) Structure and functions
Answer: b
Explanation: Class and structure are similar to each other. Only major difference is that a
structure doesn’t have member functions whereas the class can have both data
members and member functions.

5. Instance of which type of class can’t be created?


a) Anonymous class
b) Nested class
c) Parent class
d) Abstract class
Answer: d
Explanation: Instance of abstract class can’t be created as it will not have any constructor
of its own, hence while creating an instance of class, it can’t initialize the object
members. Actually the class inheriting the abstract class can have its instance, because
it will have implementation of all members.

1|Object Oriented Programming MCQs


6. If a local class is defined in a function, which of the following is true for an object of that
class?
a) Object is accessible outside the function
b) Object can be declared inside any other function
c) Object can be used to call other class members
d) Object can be used/accessed/declared locally in that function.
Answer: d
Explanation: For an object which belongs to a local class, it is mandatory to declare and
use the object within the function because the class is accessible locally within the class
only.

7. When an object is returned___________


a) A temporary object is created to return the value
b) The same object used in function is used to return the value
c) The Object can be returned without creation of temporary object
d) Object are returned implicitly, we can’t say how it happens inside program
Answer: a
Explanation: A temporary object is created to return the value. It is created because
object used in function is destroyed as soon as the function is returned. The temporary
variable returns the value and then gets destroyed.

8. If a function can perform more than 1 type of tasks, where the function name remains
same, which feature of OOP is used here?
a) Encapsulation
b) Inheritance
c) Polymorphism
d) Abstraction
Answer: c
Explanation: For the feature given above, the OOP feature used is Polymorphism.
Example of polymorphism in real life is a kid, who can be a student, a son, a brother
depending on where he is.

9. Which feature may be violated if we don’t use classes in a program?


a) Inheritance can’t be implemented
b) Object must be used is violated
c) Encapsulation only is violated
d) Basically all the features of OOP gets violated
Answer: d
Explanation: All the features are violated because Inheritance and Encapsulation won’t
be implemented. Polymorphism and Abstraction is still possible in some cases, but the
main features like data binding, object use and etc won’t be used hence use of class is
must for OOP concept.

10. ___________ underlines the feature of Polymorphism in a class.


a) Nested class
b) Enclosing class
c) Inline function
d) Virtual Function
Answer: d

2|Object Oriented Programming MCQs


11. Which feature in OOP is used to allocate additional function to a predefined operator in
any language?
a) Operator Overloading
b) Function Overloading
c) Operator Overriding
d) Function Overriding
Answer: a
Explanation: The feature is operator overloading. There is not feature named operator
overriding specifically. Function overloading and overriding doesn’t give addition function
to any operator.

12. Which among doesn’t illustrates polymorphism?


a) Function overloading
b) Function overriding
c) Operator overloading
d) Virtual function
Answer: b

13. OOP provides better security than POP:


a) Always true for any programming language
b) May not be true with respect to all programming languages
c) It depends on type of program
d) It’s vice-versa is true
Answer: a
Explanation: It is always true as we have the facility of private and protected access
specifiers. Also, only the public and global data is available globally or else program
should have proper permission to access the private data.

14. 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
Answer: a

15. What do you call the languages that support classes but not polymorphism?
a) Class based language
b) Procedure Oriented language
c) Object-based language
d) If classes are supported, polymorphism will always be supported
Answer: c

16. If same message is passed to objects of several different classes and all of those can
respond in a different way, what is this feature called?
a) Inheritance
b) Overloading
c) Polymorphism
d) Overriding
Answer: c

3|Object Oriented Programming MCQs


17. Which type of function among the following shows polymorphism?
a) Inline function
b) Virtual function
c) Undefined functions
d) Class member functions
Answer: b

18. In case of using abstract class or function overloading, which function is supposed to be
called first?
a) Local function
b) Function with highest priority in compiler
c) Global function
d) Function with lowest priority because it might have been halted since long time,
because of low priority
Answer: b

19. Which problem may arise if we use abstract class functions for polymorphism?
a) All classes are converted as abstract class
b) Derived class must be of abstract type
c) All the derived classes must implement the undefined functions
d) Derived classes can’t redefine the function
Answer: c

20. If data members are private, what can we do to access them from the class object?
a) Create public member functions to access those data members
b) Create private member functions to access those data members
c) Create protected member functions to access those data members
d) Private data members can never be accessed from outside the class
Answer: a

21. Encapsulation helps in writing ___________ classes in java


a) Mutable
b) Abstract
c) Wrapper
d) Immutable
Answer: d

22. How can Encapsulation be achieved?


a) Using Access Specifiers
b) Using only private members
c) Using inheritance
d) Using Abstraction
Answer: a

23. Which among the following violates the principle of encapsulation almost always?
a) Local variables
b) Global variables
c) Public variables
d) Array variables
Answer: b

4|Object Oriented Programming MCQs


24. Which among the following would destroy the encapsulation mechanism if it was allowed
in programming?
a) Using access declaration for private members of base class
b) Using access declaration for public members of base class
c) Using access declaration for local variable of main() function
d) Using access declaration for global variables
Answer: a
Explanation: If using access declaration for private members of base class was allowed
in programming, it would have destroyed whole concept of encapsulation. As if it was
possible, any class which gets inherited privately, would have been able to inherit the
private members of base class, and hence could access each and every member of base
class.

25. Abstraction gives higher degree of ________


a) Class usage
b) Program complexity
c) Idealized interface
d) Unstable interface
Answer: c

26. Which among the following is true for copy constructor?


a) The argument object is passed by reference
b) It can be defined with zero arguments
c) Used when an object is passed by value to a function
d) Used when a function returns an object
Answer: b

27. Which constructor is called while assigning some object with another?
a) Default
b) Parameterized
c) Copy
d) Direct assignment is used
Answer: c

28. When and how many times a static constructor is called?


a) Created at time of object destruction
b) Called at first time when an object is created and only one time
c) Called at first time when an object is created and called with every new object creation
d) Called whenever an object go out of scope
Answer: b

29. Default constructor initializes all data members as:


a) All numeric member with some garbage values and string to random string
b) All numeric member with some garbage values and string to null
c) All numeric member with zero and strings to random value
d) All numeric member with zero and strings to null
Answer: d

5|Object Oriented Programming MCQs


30. Which type of constructor can’t have a return type?
a) Default
b) Parameterized
c) Copy
d) Constructors don’t have a return type
Answer: d

31. Which among the following best defines single level inheritance?
a) A class inheriting a derived class
b) A class inheriting a base class
c) A class inheriting a nested class
d) A class which gets inherited by 2 classes
Answer: b

32. Which type of inheritance leads to diamond problem?


a) Single level
b) Multi-level
c) Multiple
d) Hierarchical
Answer: c

6|Object Oriented Programming MCQs

Das könnte Ihnen auch gefallen