Which of the following feature is used in function overloading and fun...
Polymorphism is the correct answer.
Explanation:
Polymorphism is a fundamental concept in object-oriented programming that allows objects to have different forms or behaviors. It enables a single interface to represent multiple types of objects. Two common ways to achieve polymorphism in programming are function overloading and function with default argument.
Function Overloading:
Function overloading is a feature in programming languages that allows multiple functions with the same name but different parameters or arguments. These functions can perform similar tasks but with different input types or numbers of arguments. The compiler determines which function to execute based on the arguments passed during the function call. Function overloading provides flexibility and code reusability.
For example, consider a function called calculateArea. We can define multiple versions of this function with different parameter lists, such as one that calculates the area of a rectangle and another that calculates the area of a circle. When we call the calculateArea function with the respective arguments, the appropriate version of the function will be executed based on the argument types.
Function with Default Argument:
A function with default arguments is a function that allows some of its parameters to have default values. If a value is not provided for those parameters during the function call, the default values are used instead. This feature provides flexibility and simplifies function calls by reducing the number of arguments required.
For example, consider a function called printMessage that takes two arguments: message and count. By providing a default value for the count parameter, such as 1, we can call the function with just the message argument. The function will use the default value for the count parameter if no value is specified explicitly.
In conclusion, both function overloading and functions with default arguments are examples of polymorphism, which is the ability of objects or functions to take on different forms or behaviors. They enhance code reusability and flexibility in programming.
Which of the following feature is used in function overloading and fun...
Both of the above types allows a function overloading which is the basic concept of Polymorphism.
To make sure you are not studying endlessly, EduRev has designed Class 7 study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Class 7.