KnowledgeBoat Logo
|

Computer Applications

Which of the following function-definitions are overloading the method given below :

int sum(int x, int y) {}
  1. int sum(int x, int y, int z) { }
  2. float sum(int x, int y) { }
  3. int sum (float x, float y) { }
  4. int sum (int a, int b) { }
  5. float sum(int x, int y, float z) { }

User Defined Methods

2 Likes

Answer

  1. int sum(int x, int y, int z) { }
  2. int sum (float x, float y) { }
  3. 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