250+ TOP MCQs on Abstract Function and Answers Quiz Exam

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on ” Abstract Function”.

1. Which among the following best defines the abstract methods?
a) Functions declared and defined in base class
b) Functions only declared in base class
c) Function which may or may not be defined in base class
d) Function which must be declared in derived class

Answer: b
Clarification: The abstract functions must only be declared in base class. Their definitions are provided by the derived classes. It is a mandatory condition.

2. Which among the following is true?
a) The abstract functions must be only declared in derived classes
b) The abstract functions must not be defined in derived classes
c) The abstract functions must be defined in base and derived class
d) The abstract functions must be defined either in base or derived class

Answer: a
Clarification: The abstract functions can’t be defined in base class. They are to be defined in derived classes. It is a rule for abstract functions.

3. How are abstract functions different from the abstract functions?
a) Abstract must not be defined in base class whereas virtual function can be defined
b) Either of those must be defined in base class
c) Different according to definition
d) Abstract functions are faster

Answer: a
Clarification: The abstract functions are only declared in base class. Derived classes have to implement those functions in order to inherit that base class. The functions are always defined in derived classes only.

4. 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

Answer: d
Clarification: 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.

5. 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

Answer: c
Clarification: 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.

6. The abstract function definitions in derived classes is enforced at _________
a) Runtime
b) Compile time
c) Writing code time
d) Interpreting time

Answer: b
Clarification: 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.

7. 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

Answer: c
Clarification: 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.

8. 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)

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

9. 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

Answer: b
Clarification: 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.

10. Static methods can’t be made abstract in java.
a) True
b) False

Answer: a
Clarification: The abstract functions can’t be made static in a program. If those are made static then the function will be a property of class rather than each object. In turn ever object or derived class must use the common definition given in the base class. But abstract functions can’t be defined in the base class. Hence not possible.

11. 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

Answer: c
Clarification: 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.

12. 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 must have different signature in derived class
d) It must have same return type only

Answer: b
Clarification: 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.

13. If a class have all the abstract methods the class will be known as ___________
a) Abstract class
b) Anonymous class
c) Base class
d) Derived class

Answer: a
Clarification: The classes containing all the abstract methods are known as abstract classes. And the abstract classes can never have any normal function with definition. Hence known as abstract class.

14. The abstract methods can never be ___________ in a base class.
a) Private
b) Protected
c) Public
d) Default

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

15. The abstract method definition can be made ___________ in derived class.
a) Private
b) Protected
c) Public
d) Private, public, or protected

Answer: d
Clarification: 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.

Leave a Reply

Your email address will not be published. Required fields are marked *