Computer Applications
Which of the following function-definitions are overloading the method given below :
int sum(int x, int y) {}
- int sum(int x, int y, int z) { }
- float sum(int x, int y) { }
- int sum (float x, float y) { }
- int sum (int a, int b) { }
- float sum(int x, int y, float z) { }
User Defined Methods
2 Likes
Answer
- int sum(int x, int y, int z) { }
- int sum (float x, float y) { }
- float sum(int x, int y, float z) { }
Reason — Function prototypes 1,3 and 5 have different signatures. Thus, they are overloading the function sum(). Prototypes 2 and 4 have same signatures as both are taking two int arguments, which will generate compile time error.
Answered By
2 Likes
Related Questions
A method declared as static cannot access non-static class members. (True/False)
A static class method can be invoked by simply using the name of the method alone. (True/False)
What is the role of void keyword in declaring functions ?
How is call-by-value way of function invoking different from call-by-reference way ? Give appropriate examples supporting your answer.