Test Series - oops

Test Number 42/78

Q: If all the classes used parameterized constructors and no default constructor then ___________
A. The object of lower level classes can’t be created
B. Object of lower level classes must call parent class constructors explicitly
C. Object of lower level classes must define all the default constructors
D. Only object of first class can be created, which is first parent
Solution: Each class constructor must be called before creating the object of any subclass. Hence it will be mandatory to call the constructors of parent classes explicitly with parameters. This will make all the previous class member be initialized and then the class in use will be able to create the object.
Q: In multilevel inheritance, which is the most significant feature of OOP used?
A. Code readability
B. Flexibility
C. Code reusability
D. Code efficiency
Solution: 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.
Q: Is it compulsory for all the classes in multilevel inheritance to have constructors defined explicitly if only last derived class object is created?
A. Yes, always
B. Yes, to initialize the members
C. No, it not necessary
D. No, Constructor must not be defined
Solution: It’s not mandatory to define the constructors explicitly. Default constructor will always be provided by the compiler itself if none another constructor is defined in those classes. If explicit default constructor is defined it will be used.
Q: Multiple inheritance is ____________________
A. When a class is derived from another class
B. When a class is derived from two or more classes
C. When a class is derived from other two derived classes
D. When a class is derived from exactly one class
Solution: The multiple inheritance is used when a class is being derived using two base classes or more. This way a single class can have features of more than one classes inherited into a single unit. This lets us combine two class members into a single class.
Q: Which problem arises due to multiple inheritance, if hierarchical inheritance is used previously for its base classes?
A. Diamond
B. Circle
C. Triangle
D. Loop
Solution: The diamond problem arises when multiple inheritance is used. This problem arises because the same name member functions get derived into a single class. Which in turn creates ambiguity in calling those methods.
Q: How many classes should a program contain to implement the multiple inheritance?
A. Only 1
B. At least 1
C. At least 3
D. Exactly 3
Solution: For the implementation of multiple inheritance, there must be at least 3 classes in a program. At least 2 base classes and one class to inherit those two classes. If lesser, it becomes single level inheritance.
Q: Which programming language restricts the use of multiple inheritance?
A. C++
B. PHP
C. SmallTalk
D. Java
Solution: Java doesn’t allow use of multiple inheritance with classes. But this can be done by using the interfaces. This is more secure and unambiguous way to implement multiple inheritance.
Q: Is it possible to have all the abstract classes as base classes of a derived class from those?
A. Yes, always
B. Yes, only if derived class implements all the methods
C. No, because abstract classes doesn’t have constructors
D. No, never
Solution: The condition for abstract class applies same here too. All the undefined functions must be defined. Hence all the base classes can be abstract but derived class must implement all those undefined functions.
Q: If class A inherits class B and class C as “class A: public class B, public class C {// class body ;}; ”, which class constructor will be called first?
A. Class A
B. Class B
C. Class C
D. All together
Solution: The constructors of parent class will be called first. In that, the constructor of the classes will be called in the same sequence as that mentioned in class definition inheritance. Since class B is mentioned first for inheritance, its constructor will be called first.
Q: Why does diamond problem arise due to multiple inheritance?
A. Methods with same name creates ambiguity and conflict
B. Methods inherited from the superclass may conflict
C. Derived class gets overloaded with more than two class methods
D. Derived class can’t distinguish the owner class of any derived method
Solution: All the derived classes can distinguish the base class members, but if a method is being inherited to the base classes from another class which again gets inherited into same class (diamond shape), that may create conflict in using the function from two available.

You Have Score    /10