You are on page 1of 9

 

Object Oriented Programming Questions and


Answers – Default Arguments
« Prev Next »

This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) focuses on
“Default Arguments”.

1. What are default arguments?


a) Arguments which are not mandatory to be passed
b) Arguments with default value that aren’t mandatory to be passed
c) Arguments which are not passed to functions
d) Arguments which always take same data value

View Answer

Answer: b
Explanation: The arguments which are assigned with some default value. Since some value is already given,
it is not mandatory to pass those arguments. They can be used directly.

advertisement


2. Which is the correct condition for the default arguments?
a) Those must be declared as last arguments in argument list
b) Those must be declared rst in the argument list
c) Those can be de ned anywhere in the argument list
d) Those are declared inside the function de nition

View Answer

Answer: a
Explanation: The default arguments must be declared at last in the argument list. This is to ensure that the
arguments doesn’t create ambiguity. The normal arguments should be passed rst.

3. If a member function have to be made both zero argument and parameterized constructor, which among
the following can be the best option?
a) Two normal and one default argument
b) At least one default argument
c) Exactly one default argument
d) Make all the arguments default

View Answer

Answer: d
Explanation: All the arguments must be made default. This will make sure that none of the arguments are
mandatory to be passed. Which in turn means that the function can work without any argument and can be
passed with arguments too.

4. Which among the following function can be called without arguments?


a) void add(int x, int y=0)
b) void add(int=0)
c) void add(int x=0, int y=0)
d) void add(char c)

View Answer

Answer: c 
Explanation: For the function to be called without arguments, either it must have zero arguments or it must
have all the default arguments. Here the function in option void add(int x=0, int y=0) have all the default
arguments and hence can be called directly with zero argument.
5. If a function have all the default arguments but still some values are passed to the function then
______________
a) The function will use the values passed to it
b) The function will use the default values as those are local
c) The function can use any value whichever is higher
d) The function will choose the minimum values

View Answer

Answer: a
Explanation: The function will use the values passed explicitly to it. The default values will be ignored. The
default values are used only in case the values are not passed explicitly to the function.

advertisement

6. Which among the following is correct?


a) void test(int x=0, int y, int z=0)
b) void test(int x=0, int=0)
c) void test(int x, int y=0)
d) void test(int x=’c, int y)

View Answer

Answer: c
Explanation: The default arguments must be mentioned at last in the argument list. Also, the type of values
assigned must match with the argument type. All the default arguments must be mentioned at last, none of
the normal arguments should come in between the default arguments list.

7. What function will be called with the independent syntax “test(5,6,7);”? 


a) void test(int x, int y)
b) void test(int x=0, int y, int z)
c) int test(int x=0, y=0, z=0)
d) void test(int x, int y, int z=0)

View Answer

Answer: d
Explanation: There are three arguments that are getting passed to the function test(). Only the last option
have all the default argument at last in the argument list. And the total number of the arguments is three.
The third option is wrong because the return type is int and the syntax given is independent which means it
doesn’t return any value.

8. Which among the following is a wrong call to the function void test(int x, int y=0, int z=0)?
a) test(5,6,7);
b) test(5);
c) test();
d) test(5,6);

View Answer

Answer: c
Explanation: The function must be passed with at least one argument. There is two default arguments and
one normal argument which must be passed with some value. Hence the third call to the function is wrong
as it doesn’t pass even a single parameter to the function

9. Default arguments are _________________________


a) Only allowed in the parameter list of the function declaration
b) Only allowed in the return type of the function declaration
c) Only allowed with the class name de nition
d) Only allowed with the integer type values

View Answer

Answer: a
Explanation: The default arguments are only allowed in the parameter list of the function arguments. This
rule was not applicable in the beginning versions of c++ but later from c++ 14th version it has been
implemented. This is the only way to use default arguments.

advertisement


10. Which among the following is false for default arguments?
a) Those are not allowed with a declaration of pointer to functions
b) Those are not allowed with the reference to functions
c) Those are not allowed with the typedef declarations
d) Those are allowed with pointer and reference to function declaration

View Answer

Answer: d
Explanation: The statements given are true because that is a feature given to make the programming more
exible and have some security with accidental changes at same time. The last option is false because it is
not a rule de ned. It is an opposite statement to the rules de ned for default arguments.

11. The non-template functions can be added with default arguments to already declared functions
____________________
a) If and only if the function is declared again in the same scope
b) If and only if the function is declared only once in the same scope
c) If and only if the function is declared in di erent scope
d) If and only if the function is declared twice in the program

View Answer

Answer: a
Explanation: The non-template functions can also be added with default arguments. This can be done even if
the functions were de ned earlier. This is because the call to the function won’t be a ected. The function can
still be used in the same way as it was used earlier.

12. The using declaration __________


a) Doesn’t carry over the default values
b) Carries over the known default arguments
c) Carries over only the normal arguments
d) Carries over only few default arguments

View Answer

Answer: b
Explanation: The using-declaration carries over all the known default arguments. This is a common feature
as the usage doesn’t gets a ected even if the default arguments are added. This comes under exible
programming. 

13. The names given to the default arguments are only looked up and ________________ and are bound during
declaration.
a) Checked for availability
b) Checked for random access
c) Checked for accessibility
d) Checked for feasibility

View Answer

Answer: c
Explanation: The names given to the default arguments are bound at time of declaration but are only
checked for accessibility and to get bounded. This is mainly to bind those members during declaration.

advertisement

14. The default argument get bound during declaration ________________


a) And are never executed
b) And are executed simultaneously
c) But are executed only if priority is given
d) But are executed during function call

View Answer

Answer: d
Explanation: The default argument are bound at the time of declaration. That is an implicit functioning. But
those are executed only when the function is called. Otherwise, those will never get executed.

15. The virtual function overrides ____________


a) Do not acquire base class declaration of default arguments
b) Do acquire base class declaration of default arguments
c) Do not link with the default arguments of base class
d) Do link with the default argument but only of derived classes 
View Answer
Answer: a
Explanation: The virtual function overrides do not acquire the base class declaration of default arguments.
Even if a call to the virtual function is made, static type of the object decides the default arguments to be
used.

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

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

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

Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest

« Prev - Object Oriented Programming Questions and Answers – This Pointer


» Next - Object Oriented Programming Questions and Answers – Constructors Overloading

advertisement

Recommended Posts:
1. C Programming Examples on Linked List
2. Java Programming Examples
3. C Programming Examples on Stacks & Queues
4. Simple C Programs
5. C Tutorials
6. C Programming Examples
7. R Programming Questions and Answers 
8. C++ Programming Examples on Data-Structures
9. C# Programming Examples on Arrays
10. C Programming Examples on Arrays
11. C Programming Examples on Strings
12. Java Programming Examples on Inheritance
13. Ruby Programming Questions and Answers
14. C# Programming Examples on Functions
15. C Programming Examples on Searching and Sorting
16. C++ Questions and Answers
17. C Programming Examples on File Handling
18. Java Programming Examples on File Handling
19. Java Programming Examples on Classes
20. Object Oriented Programming Questions and Answers

advertisement

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

Subscribe Sanfoundry Newsletter and Posts

Name*

Email*

Subscribe
About | Certi cations | Internships | Jobs | Privacy Policy | Terms | Copyright | Contact

     

© 2011-2020 Sanfoundry. All Rights Reserved.

You might also like