Test Series - oops

Test Number 34/78

Q: An abstract class is always a __________ class.
A. Base
B. Derived
C. Template
D. Nested
Solution: Every abstract class is a base class. It must be so, because the functions which are not defined inside the abstract class, must be defined in the derived classes. Hence it becomes a base class.
Q: How many base classes can a single class inherit in java?
A. 1
B. 2
C. 3
D. As many as required
Solution: In java, multiple inheritance is not supported, which leads to the fact that a class can have only 1 parent class if inheritance is used. Only if interfaces are used then the class can implement more than one base class.
Q: How to make a derived class a base class?
A. Change name of the class
B. Use keyword base
C. Make a class derive from it
D. Can’t be done
Solution: Making another class derive from it will make that class as base class. It is not necessary that we have to write different code for it. If at least one class derives that class, it becomes the base class for the new class.
Q: If a base class is being derived by two other classes, which inheritance will that be called?
A. Single
B. Multiple
C. Multi-level
D. Hierarchical
Solution: When more than one classes are being derived from a single parent class, the inheritance is known as hierarchical inheritance. This is usually useful when the base class is higher abstraction of its derived classes.
Q: Which among the following must be in a base class?
A. Data members
B. Member functions
C. Access specifiers
D. Nothing
Solution: Even a class that doesn’t have any members can be a base class. It is not mandatory to have any member or attribute in base class.
Q: Which type of members can’t be accessed in derived classes of a base class?
A. Protected
B. Private
C. Public
D. All can be accessed
Solution: 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.
Q: Base class have ________________ of abstraction.
A. Higher degree
B. Lower degree
C. Intermediate
D. Minimum degree
Solution: A base class will have lesser information as compared to those of derived classes. Since derived classes inherit the base class properties and then add on their own features, they elaborate more hence have lower degree of abstraction.
Q: Always the base class constructors are called ___________ constructor of derived class.
A. Before
B. After
C. Along
D. According to priority of
Solution: When the base class object is created, its constructor will be called for sure. But if a derived class constructor is called, first base class constructor is called and then derived class constructor is taken into consideration.
Q: Can we call methods of base class using the constructor of the derived class?
A. Yes, always
B. Yes, but not always
C. No, never
D. No, but we can call in some cases
Solution: If the function is defined in the base class, it can always be called from the constructor of its derived class. Since the constructors are not private, they can be accessed in derived class even if those are protected.
Q: If a base class is inherited from another class and then one class derives it, which inheritance is shown?
A. Multiple
B. Single
C. Hierarchical
D. Multi-level
Solution: If a base class is inherited from another class, single inheritance is shown. But when one more class inherits the derived class, this becomes a multi-level inheritance.

You Have Score    /10