Object Oriented Programming using C++ Questions and Answers – Abstract Function

«
»

This set of Object Oriented Programming (OOPs) using C++ Multiple Choice Questions & Answers (MCQs) focuses 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
View Answer

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

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
View Answer

Answer: a
Explanation: 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
View Answer

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

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
View Answer

Answer: d
Explanation: 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
View Answer

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

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

Answer: b
Explanation: 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
View Answer

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

8. What is the syntax for using abstract method?
a) <access-modifier>abstract<return-type>method_name (parameter)
b) abs<return-type>method name (parameter)
c) <access-modifier>abstract return-type method name (parameter)
d) <access-modifier>abstract <returning> method name (parameter)
View Answer

Answer: a
Explanation: 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
View Answer

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

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

Answer: a
Explanation: 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
View Answer

Answer: c
Explanation: 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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

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

Sanfoundry Global Education & Learning Series – Object Oriented Programming (OOPs).

To practice all areas of Object Oriented Programming (OOPs) using C++, here is complete set of 1000+ Multiple Choice Questions and Answers.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter