Test Series - oops

Test Number 48/78

Q: Which among the following is correct?
A. Abstract functions should not be defined in all the derived classes
B. Abstract functions should be defined only in one derived class
C. Abstract functions must be defined in base class
D. Abstract functions must be defined in all the derived classes
Solution: The abstract function are only declared in base classes and then has to be defined in all the derived classes. This allows all the derived classes to define own definition of any function whose declaration in base class might be common to all the other derived classes.
Q: It is ____________________ to define the abstract functions.
A. Mandatory for all the classes in program
B. Necessary for all the base classes
C. Necessary for all the derived classes
D. Not mandatory for all the derived classes
Solution: The derived classes must define the abstract function of base class in their own body. This is a necessary condition. Because the abstract functions doesn’t contain any definition in base class and hence becomes mandatory for the derived class to define them. All the functions in a program must have some definition.
Q: The abstract function definitions in derived classes is enforced at _________
A. Runtime
B. Compile time
C. Writing code time
D. Interpreting time
Solution: When the program is compiled, these definitions are checked if properly defined. This compiler also ensure that the function is being defined by all the derived classes. Hence we get a compile time error if not done.
Q: What is this feature of enforcing definitions of abstract function at compile time called?
A. Static polymorphism
B. Polymorphism
C. Dynamic polymorphism
D. Static or dynamic according to need
Solution: The feature is known as Dynamic polymorphism. Because the definitions are resolved at runtime. Even though the definitions are checked at compile time, they are resolved at runtime only.
Q: What is the syntax for using abstract method?
A. abstractmethod_name (parameter)
B. absmethod name (parameter)
C. abstract return-type method name (parameter)
D. abstract method name (parameter)
Solution: The syntax must firstly contain the access modifier. Then the keyword abstract is written to mention clearly to the compiler that it is an abstract method. Then prototype of the function with return type, function name and parameters.
Q: If a function declared as abstract in base class doesn’t have to be defined in derived class then ______
A. Derived class must define the function anyhow
B. Derived class should be made abstract class
C. Derived class should not derive from that base class
D. Derived class should not use that function
Solution: If the function that is not to be defined in derived class but is declared as abstract in base class then the derived class must be made an abstract class. This will make the concept mandatory that the derived class must have one subclass to define that method.
Q: Which among the following is true?
A. Abstract methods can be static
B. Abstract methods can be defined in derived class
C. Abstract methods must not be static
D. Abstract methods can be made static in derived class
Solution: The abstract methods can never be made static. Even if it is in derived class, it can’t be made static. If this happens, then all the subsequent sub classes will have a common definition of abstract function which is not desirable.
Q: Which among the following is correct for abstract methods?
A. It must have different prototype in the derived class
B. It must have same prototype in both base and derived class
C. It mPublicust have different signature in derived class
D. It must have same return type only
Solution: The prototype must be the same. This is to override the function declared as abstract in base class. Or else it will not be possible to override the abstract function of base class and hence we get a compile time error.
Q: The abstract methods can never be ___________ in a base class.
A. Private
B. Protected
C. Public
D. Default
Solution: The base class must not contain the abstract methods. The methods have to be derived and defined in derived class. But if it is made private it can’t be inherited. Hence we can’t declare it as a private member.
Q: The abstract method definition can be made ___________ in derived class.
A. Private
B. Protected
C. Public
D. Private, public, or protected
Solution: The derived class implements the definition of the abstract methods of base class. Those can be made private in derived class if security is needed. There won’t be any problem in declaring it as private.

You Have Score    /10