Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Why is downcasting possible in any language?(a) Because inheritance follows has-a relationship(b) Because inheritance follows is-a relationship(c) Because inheritance doesn’t follow any relationship(d) Because inheritance is not involved in castingI had been asked this question in homework.My doubt stems from Downcasting topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right option is (b) Because inheritance follows is-a relationship

For explanation: The downcasting is POSSIBLE because the CLASSES in inheritance follow is-a relationship. HENCE the DERIVED class is a base class. Which in turn make the downcasting possible.

2.

When is the downcasting used?(a) To separate inherited class from base class(b) To write a more complex code(c) To compare two objects(d) To disable one class in inheritanceI have been asked this question during a job interview.I'm obligated to ask this question of Downcasting in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right choice is (c) To compare two objects

Easiest explanation - The downcasting can be used WHENEVER there is a need to compare ONE object to another. Equals() function can be used to compare whether the objects were of same age. We can USE GETCLASS() function too.

3.

What happens when downcasting is done but not explicitly defined in syntax?(a) Compile time error(b) Runtime error(c) Code write time error(d) Conversion errorI had been asked this question in an interview for job.Asked question is from Downcasting in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Correct choice is (a) Compile time error

The best explanation: The IMPLICIT DOWNCASTING is not possible. If tried, the COMPILER PRODUCES an error. Since the compiler doesn’t allow coasting to a type that is not compatible.

4.

Which way the downcasting is possible with respect to inheritance?(a) Upward the inheritance order(b) Downward the inheritance order(c) Either upward or downward the inheritance order(d) Order of inheritance doesn’t matterI have been asked this question in homework.I'd like to ask this question from Downcasting in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right choice is (b) DOWNWARD the inheritance order

Best explanation: The downcasting is always downward the inheritance order. Since the BASE class object have to be casted into derived class TYPE. This is a BASIC DEFINITION of downcasting.

5.

Java supports direct downcasting.(a) True(b) FalseThis question was addressed to me in unit test.The origin of the question is Downcasting in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Correct option is (b) False

The BEST explanation: The downcasting is not possible in java directly. This has to be done explicitly. The downcasting is not SAFE but can be checked for safe casting USING instanceof FUNCTION.

6.

How to prevent the ClassCastExceptions?(a) By using instanceof(b) By using is-a check(c) By using arrow operator with check function(d) By checking type of conversionI have been asked this question during an interview.The above asked question is from Downcasting topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right CHOICE is (a) By using INSTANCEOF

For explanation: The instanceof operator can be USED to CHECK the compatibility of the conversion. This has to be done to check WHETHER the casting would be safe or not.

7.

Which is the exception handler for the exceptions of downcasting?(a) CastException(b) ClassCastingExeption(c) ClassCasting(d) ClassCastExceptionThe question was asked during an online interview.Enquiry is from Downcasting topic in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer» RIGHT ANSWER is (d) ClassCastException

Easy explanation - The exception handler for the exceptions PRODUCED during the DOWNCASTING exception. This handler can be called during runtime to handle any exception thrown.
8.

Which is the proper syntax of dynamic_cast?(a) dynamic_cast(object)(b) dynamic_cast new (object)(c) dynamic_cast(object)(d) dynamic_cast(object)This question was addressed to me in my homework.Question is from Downcasting in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

The correct CHOICE is (c) dynamic_cast(object)

For explanation: The dynamic_cast is the name of the operator, which is FOLLOWED by the NEW type in which the object have to be converted. Then the object name is GIVEN. This object name is then USED after the type conversion.

9.

If dynamic_cast fails, which value is returned?(a) void(b) null(c) void pointer(d) null pointerI had been asked this question in an internship interview.This key question is from Downcasting in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right answer is (d) null pointer

Easy EXPLANATION - The null pointer is RETURNED by the dynamic_cast, if it fails. The conversion sometimes fails because of too complex type conversion. The conversion MAY also fail DUE to memory or some RELATED issues.

10.

What does dynamic_cast return after successful type casting?(a) Address of object which is converted(b) Address of object that is used for conversion(c) Address of object that is mentioned in the syntax(d) Doesn’t return any addressI had been asked this question during an interview for a job.My question comes from Downcasting topic in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

The correct answer is (a) Address of OBJECT which is CONVERTED

For EXPLANATION: The address of the object which is converted is RETURNED by the dynamic_cast operator. This is done to safely convert the subtype to supertype. This ensures the proper assignment and conversion from ONE type to another.

11.

What should be used for safe downcast?(a) Static cast(b) Dynamic cast(c) Manual cast(d) Implicit castThe question was asked in an online quiz.This key question is from Downcasting in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Correct option is (b) Dynamic cast

The best I can explain: The dynamic cast can be done USING the operator dynamic_cast. This converts one TYPE to another type in a SAFE way.

12.

Downcasting ____________________(a) Can result in unexpected results(b) Can’t result in unexpected result(c) Can result only in out of memory error(d) Can’t result in any errorI have been asked this question during an interview for a job.The query is from Downcasting topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer» RIGHT OPTION is (a) Can result in unexpected results

To explain: The result of downcasting can be unexpected. This is because downcasting is done on the objects into the objects which doesn’t CONTAIN any information of DATA in lateral object.
13.

Downcasting is _______________________(a) Always safe(b) Never safe(c) Safe sometimes(d) Safe, depending on codeI had been asked this question during an interview.This question is from Downcasting in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right choice is (b) Never safe

For explanation: The downcasting concept is made for exception cases. When there is a NEED to represent an entity in the FORM which is not suitable for it. Representing a base TYPE in DERIVED type is not right but can be done for special cases.

14.

Which among the following is a mandatory condition for downcasting?(a) It must not be done explicitly(b) It must be done implicitly(c) It must be done explicitly(d) It can’t be done explicitlyThe question was asked in my homework.This intriguing question comes from Downcasting in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right OPTION is (c) It must be DONE explicitly

Best EXPLANATION: The downcasting of any object must be done explicitly. This is because the compilers don’t support the implicit CONVERSION of a supertype to subtype.

15.

What is downcasting?(a) Casting subtype to supertype(b) Casting supertype to subtype(c) Casting subtype to supertype and vice versa(d) Casting anytype to any other typeI got this question in exam.My query is from Downcasting in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right OPTION is (b) Casting supertype to subtype

Explanation: The downcasting concept INCLUDES only the casting of supertypes to the sub types. This casting is generally done EXPLICITLY. Larger SIZE types are made to fit into SMALL size types explicitly.

16.

Which among the following is true?(a) Upcasting is possible only for single level inheritance(b) Upcasting is possible only for multilevel inheritance(c) Upcasting is possible only for multiple inheritance(d) Upcasting is possible for any type of inheritanceI had been asked this question in my homework.The query is from Upcasting topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

The correct option is (d) UPCASTING is possible for any TYPE of inheritance

The EXPLANATION: The type of inheritance doesn’t matter with the upcasting CONCEPT. Upcasting APPLIES to all types of inheritance. Any derived class object can be upcasted to any of its base class object.

17.

If two classes are defined “Parent” and “Child” then which is the correct type upcast syntax in C++?(a) Parent *p=child;(b) Parent *p=*child;(c) Parent *p=&child;(d) Parent *p=Child();The question was asked by my school principal while I was bunking the class.My question is from Upcasting topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer» CORRECT CHOICE is (c) Parent *p=&child;

Easy explanation - The SYNTAX MUST CONTAIN the base class name first. So that the parent class object pointer can be declared. Then the object is assigned with the derived class object with & symbol. & symbol is added to get the address of the derived class object.
18.

When are the object type known for upcasting the objects?(a) Compile time(b) Runtime(c) Source code build time(d) Doesn’t apply to objects directlyI got this question in exam.This intriguing question originated from Upcasting topic in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer» RIGHT option is (b) Runtime

Best explanation: The upcasting with objects directly requires runtime resolving. The objects are fixed and address are ALLOCATED at compile time. But the execution of a program requires runtime knowledge of object TYPES, for implicit type CAST.
19.

When are the pointer types known for upcasting the objects?(a) Compile time(b) Runtime(c) Source code build time(d) Doesn’t apply to pointer typesThis question was addressed to me by my school teacher while I was bunking the class.My doubt is from Upcasting in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

The CORRECT option is (a) Compile time

Best explanation: The pointer or REFERENCE types are known at compile time for the upcasting of an object. This is because the ADDRESSES must be known for CASTING the derived CLASS to base class object.

20.

Which concept is needed because of implicit type casting use?(a) Static binding(b) Dynamic binding(c) Compile time binding(d) Source code bindingI had been asked this question by my college professor while I was bunking the class.Origin of the question is Upcasting topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right option is (b) Dynamic binding

The best explanation: SINCE the implicit type casting ALLOWS casting of a base class pointer to refer to its derived class OBJECT or even base class object. We need dynamic type casting so that the references can be RESOLVED during execution of program.

21.

Upcasting is _____________________ without an explicit type cast.(a) Always allowed for public inheritance(b) Always allowed for protected inheritance(c) Always allowed for private inheritance(d) Not allowedI got this question in a national level competition.I'm obligated to ask this question of Upcasting topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right ANSWER is (a) ALWAYS allowed for public inheritance

The best EXPLANATION: The public inheritance shows the most flexible is-a relationship. Hence explicit TYPE casting is not required. Implicit type casting is DONE by the compiler.

22.

If class C inherits class B and class B inherits class A ________________(a) Class C object can be upcasted to object of class B only(b) Class C object can be upcasted to object of class A only(c) Class C object can be upcasted to object of either class A or B(d) Class C object can’t be upcastedThis question was addressed to me in a national level competition.My doubt stems from Upcasting in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer» RIGHT OPTION is (c) Class C OBJECT can be upcasted to object of EITHER class A or B

The explanation is: Both class A and B are parent classes of class C. Class C object hence can be upcasted to any of those class objects. It is not compulsory to upcast to nearest parent.
23.

If multiple inheritance is implemented, which upcasting will be correct?(a) Upcast to first base class listed in inheritance(b) Upcast to send base class listed in inheritance(c) Upcast to any base class(d) Upcast is not possibleThe question was asked in final exam.This question is from Upcasting in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right answer is (C) Upcast to any BASE CLASS

The BEST I can explain: The upcasting of derived class object is possible to any base class. This is because the base class object can represent any of its derived classes USING upcasting.

24.

Upcasting and downcasting objects are the same as casting primitive types.(a) True(b) FalseThe question was posed to me in my homework.My query is from Upcasting topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right option is (b) False

Easy explanation - It is a bit confusing concept since both casting CONCEPTS are different. Primitive casting DEPENDS on the TYPE and size of DATA being typecast. Whereas in objects casting, the classes and inheritance order plays a big role.

25.

Which property is shown most when upcasting is used?(a) Code reusability(b) Code efficiency(c) Complex code simple syntax(d) EncapsulationThis question was addressed to me in final exam.The query is from Upcasting in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right option is (c) Complex code simple syntax

For explanation: The code WRITTEN USING upcasting mostly SHOWS complex code in simpler syntax FEATURES. This is because the upcasting concept can be applied as polymorphism and to group the similar type of OBJECTS.

26.

Which among the following is the best situation to use upcasting?(a) For general code dealing with only subtype(b) For general code dealing with only supertype(c) For general code dealing with both the supertype and subtype(d) For writing a rigid code with respect to subtypeThe question was posed to me in an interview for job.This is a very interesting question from Upcasting in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right answer is (b) For general code DEALING with only supertype

Best explanation: When a general code has to be written where we USE only the supertype object or the data of bigger size, then upcasting would be the best OPTION. Since the WHOLE code will require only the supertype name references.

27.

Which among the following is safe?(a) Upcasting(b) Downcasting(c) Both upcasting and downcasting(d) If upcasting is safe then downcasting is not, and vice versaI have been asked this question in unit test.Asked question is from Upcasting in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right option is (a) UPCASTING

The explanation: The upcasting is always safe since the derived TYPE or the SMALLER type is converted into the base type or the larger size. This results in ALLOCATING a smaller size data into bigger type data. No data is lost in casting, hence safe.

28.

Which among the following is true for upcasting in inheritance?(a) Downward to the inheritance tree(b) Upward to the inheritance tree(c) Either upward or downward(d) Doesn’t apply on inheritanceThe question was posed to me in quiz.My question comes from Upcasting in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right answer is (b) UPWARD to the INHERITANCE tree

For explanation: The upcasting concept in inheritance is ALWAYS APPLIED upward the inheritance tree. The derived class objects can be type casted to any of its parent class type. Since is a relationship APPLIES in general inheritance.

29.

What is upcasting?(a) Casting subtype to supertype(b) Casting super type to subtype(c) Casting subtype to super type and vice versa(d) Casting anytype to any other typeThis question was addressed to me by my college professor while I was bunking the class.This interesting question is from Upcasting topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right option is (a) CASTING subtype to supertype

To explain I WOULD say: The UPCASTING concept INCLUDES only the casting of subtypes to the super types. This casting is GENERALLY done implicitly. Smaller size types can fit into larger size types implicitly.

30.

Which is a good alternative instead of having one zero argument constructor and one single argument constructor with default argument?(a) No constructor defined(b) One default value constructor(c) Defining the default constructor(d) Using one constructor with two argumentsThis question was posed to me by my college professor while I was bunking the class.My doubt is from Constructors Overloading topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Correct ANSWER is (B) One default VALUE constructor

For explanation: The constructor with one default ARGUMENT can be the best alternative. This is because the constructor with one default value will do the WORK for both the default constructor and one argument constructor.

31.

Which is the correct statement for default constructors?(a) The constructors with all the default arguments(b) The constructors with all the null and zero values(c) The constructors which can’t be defined by programmer(d) The constructors with zero argumentsThis question was addressed to me in semester exam.The origin of the question is Constructors Overloading in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer» RIGHT option is (d) The constructors with zero ARGUMENTS

The EXPLANATION is: The closest answer to the QUESTION is that a default constructor is a constructor with zero arguments. But this is not the actual case. Actually the constructors provided by the compiler are default constructors. And the constructors with zero arguments defined by the programmer are zero ARGUMENT constructors.
32.

If there is a constructor with all the default arguments and arguments are not passed then _________________(a) The default values given will not be used(b) Then all the null values will be used(c) Then all the default values given will be used(d) Then compiler will produce an errorThis question was posed to me in homework.I need to ask this question from Constructors Overloading topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer» RIGHT answer is (C) Then all the default values GIVEN will be used

Best explanation: The CONSTRUCTORS will use the default values listed for use. The null values are not used because those are not specified. Though if it was compiler PROVIDED default constructor, then it would have initialized the members to null or zero values.
33.

Which constructor definition will produce a compile time error?(a) className(int x=0);(b) className(char c);(c) className(int x=0,char c);(d) className(char c,int x=0);I have been asked this question by my college director while I was bunking the class.Enquiry is from Constructors Overloading in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Correct answer is (c) className(INT x=0,char c);

To EXPLAIN: The default ARGUMENTS, just like with member functions, must be listed at last in the ARGUMENT list. Hence this will produce a COMPILE time error. The compiler doesn’t allow the definition to be executed.

34.

Which constructor among the following will be called if a call is made like className(5,’a’);?(a) className(int x=5,char c=’a’);(b) int className(int x, char c, char d);(c) className(int x, char c, int y);(d) char className(char c,int x);I got this question by my school principal while I was bunking the class.The origin of the question is Constructors Overloading in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Correct answer is (a) className(int x=5,CHAR c=’a’);

Best explanation: The SYNTAX given is passing two PARAMETERS to the constructor CALL. One value is of integer type and another of character type. Hence the constructor with arguments of int and char type should be called. There is only one option that first accepts integer value and then a character value. Hence that constructor will be called.

35.

Which among the following is true?(a) More than one constructors with all default arguments is allowed(b) More than one constructors with all default arguments can be defined outside the class(c) More than one constructors can be used with same argument list(d) More than one constructors with all default arguments can’t exist in same classThe question was asked in an international level competition.My doubt is from Constructors Overloading topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer» RIGHT choice is (d) More than one constructors with all default arguments can’t EXIST in same class

For EXPLANATION: The constructors must have DIFFERENT ARGUMENT list. Along that, if all the arguments are default arguments, there can’t be more than once constructor like that in the same class as that will create ambiguity while constructors are being called.
36.

If the constructors are overloaded by using the default arguments, which problem may arise?(a) The constructors might have all the same arguments except the default arguments(b) The constructors might have same return type(c) The constructors might have same number of arguments(d) The constructors can’t be overloaded with respect to default argumentsI have been asked this question in an interview for job.My enquiry is from Constructors Overloading in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer» RIGHT option is (a) The CONSTRUCTORS might have all the same arguments except the default arguments

The best explanation: The constructors having same arguments except the default arguments can give rise to ERRORS. If only the mandatory arguments are passed, it will create ambiguity in calling the correct CONSTRUCTOR. Hence the mandatory arguments must be different.
37.

Which is the correct syntax for using default arguments with the constructor?(a) default constructorName(default int x=0)(b) constructorName(default int x=0)(c) constructorName(int x=0)(d) constructorName()This question was posed to me in unit test.I want to ask this question from Constructors Overloading in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer» RIGHT answer is (c) constructorName(INT x=0)

To explain I would say: The constructors using the default arguments must initialize the arguments in the ARGUMENT LIST. This is to make the CONSTRUCTOR use the default value when no arguments are passed. If no arguments are listed then it is a default constructor.
38.

Can a class have more than one function with all the default arguments?(a) Yes, always(b) Yes, if argument list is different(c) No, because constructors overloading doesn’t depend on argument list(d) No, neverThis question was addressed to me by my college professor while I was bunking the class.I'm obligated to ask this question of Constructors Overloading in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right option is (d) No, never

Best explanation: A single class can never have more than once CONSTRUCTOR with all the default arguments. This is because it will MAKE all those CONSTRUCTORS as a default constructor. And when an object is CREATED with zero arguments then it will CREATE ambiguity.

39.

Which among the following can be used in place of default constructor?(a) constructorName(int x, int y=0)(b) constructorName(int x=0, int y=0)(c) constructorName(int x=0, int y)(d) constructorName(int x, int y)I got this question by my school principal while I was bunking the class.This intriguing question originated from Constructors Overloading topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

The CORRECT answer is (B) CONSTRUCTORNAME(int x=0, int y=0)

Easiest explanation - For a parameterized constructor to be used as a default constructor, it must have all the default arguments. This MAKES the constructor to have optional arguments which are not mandatory to be passed.

40.

Which among the following is true?(a) The constructors overloading can be done by using different names(b) The constructors overloading can be done by using different return types(c) The constructors can be overloaded by using only one argument(d) The constructors must have the same name as that of classThis question was posed to me during an interview.Origin of the question is Constructors Overloading in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Correct option is (d) The constructors MUST have the same name as that of class

To EXPLAIN I would say: The constructors must have the same name as that of the class name. This is mandatory because only the constructor FUNCTIONS doesn’t have any return TYPE. ALSO, for overloading all the functions must have the same name.

41.

The Constructors with all the default arguments are similar as default constructors.(a) True(b) FalseI have been asked this question in homework.I'd like to ask this question from Constructors Overloading topic in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer» CORRECT choice is (a) True

The explanation: The constructors with all the default ARGUMENTS are similar as the default constructors. Those can be used instead of the default constructors. So DEFINING the default CONSTRUCTOR is not mandatory.
42.

If a constructors should be capable of creating objects without argument and with arguments, which is a good alternative for this purpose?(a) Use zero argument constructor(b) Use constructor with one parameter(c) Use constructor with all default arguments(d) Use default constructorI had been asked this question in homework.My enquiry is from Constructors Overloading topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Correct OPTION is (C) Use constructor with all default arguments

The best I can explain: The constructor should use all the default arguments. This will ALLOW the constructor to be called even if no arguments are passed. And if arguments are passed, those will be accepted INSTEAD of the default values.

43.

Which among the following is true for constructors overloading?(a) Constructors can’t be overloaded(b) Constructors can be overloaded using different signatures(c) Constructors can be overloaded with same signatures(d) Constructors can be overloaded with different return typesI have been asked this question during an interview.My question is based upon Constructors Overloading in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right option is (B) Constructors can be overloaded USING different SIGNATURES

The BEST explanation: The constructors can be overloaded only if the DEFINITIONS have different signatures. Constructors doesn’t have any return type so can’t be overloaded using return type. If constructors have same signature then it will produce a compile time error.

44.

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 classesI got this question in an interview.I want to ask this question from Default Arguments topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right option is (a) Do not acquire base class declaration of default arguments

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

45.

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 callI had been asked this question in class test.This is a very interesting question from Default Arguments topic in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

The correct choice is (d) But are executed during FUNCTION call

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

46.

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 feasibilityThis question was posed to me in an internship interview.This intriguing question comes from Default Arguments in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer» RIGHT ANSWER is (C) Checked for accessibility

To EXPLAIN I would say: 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.
47.

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 argumentsI got this question during an interview.Asked question is from Default Arguments topic in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right choice is (B) Carries over the known DEFAULT arguments

The EXPLANATION is: The using-declaration carries over all the known default arguments. This is a common FEATURE as the usage doesn’t gets affected even if the default arguments are added. This comes under FLEXIBLE programming.

48.

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 different scope(d) If and only if the function is declared twice in the programThe question was asked during an online exam.Question is taken from Default Arguments topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right answer is (a) If and only if the function is declared again in the same scope

To EXPLAIN I WOULD say: The non-template functions can also be added with default arguments. This can be done even if the functions were defined earlier. This is because the call to the function won’t be affected. The function can still be USED in the same way as it was used earlier.

49.

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 declarationI have been asked this question in exam.My question is based upon Default Arguments topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Correct choice is (d) Those are allowed with pointer and reference to function declaration

Easy EXPLANATION - The statements GIVEN are true because that is a feature given to MAKE the PROGRAMMING more flexible and have some security with accidental changes at same time. The last option is false because it is not a rule defined. It is an opposite statement to the rules defined for DEFAULT arguments.

50.

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 definition(d) Only allowed with the integer type valuesI have been asked this question in a job interview.My doubt is from Default Arguments topic in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

The CORRECT option is (a) Only allowed in the parameter list of the FUNCTION declaration

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.