5,421 views
4 votes
4 votes
What is the difference between overloaded functions and overridden functions?

a. Overloading is a dynamic or run-time binding and Overriding is static or compile-time binding

b. Redefining a function in a friend class is called function overriding while Redefining a function in a derived class is called a overloaded fucntion.

c. Overloading is a static or compile-time binding and Overriding is dynamic or run-time binding

d. Redefining a function in a friend class is called function overloading while Redefining a function in a derived class is called as overridden function.

1 Answer

Best answer
2 votes
2 votes

Option (c) is correct.

Function overloading is static or compile-time binding whereas function overriding is dynamic or run-time binding. The reason is that in overloading, two functions sharing the same name have different set of parameters (function signature) and with that different signature, the compiler can easily identify to which function is this call associated. So compile-time bnding is possible and is preferred. In contrast, overriden functions always have exactly same signature in the derived class. So the decision is deferred until run-time, where the JVM decides which function to bind to the call.

Option (d) is also correct. Overrriding applies to derived classes whereas overloading applies to functions in the same class or friend classes. Overloading in same class is obvious, but how it applies to friend classes is given in the example below:

class Rectangle{
    int width, height;
  public:
    int area() {return (width * height);}
};

class Square{
  friend class Rectangle;
  private:
    int side;
  public:   
   Square (int a) : side(a) {}
   int area(int a) : side(a) {return (a * a);}
};

Here, class Rectangle is a friend of class Square. So a non-member function of Rectangle can have access to all private and protected data / functions of class Square. The function area() is overloaded in the friend class Rectangle.

Thus the correct answers are (c) and (d).

selected by

Related questions

2 votes
2 votes
1 answer
1
sh!va asked Aug 11, 2016
306 views
What fearure(s) can differ between two overloaded functions?a. Number of parametrsb. type of parametersc. Return type.I. a , b, or cII.( a and b) or cIII. a and b onlyIV...
2 votes
2 votes
1 answer
2
sh!va asked Aug 10, 2016
15,015 views
If class A is friend of class B and if class B is friend of class C, which of the following is true?a. Class C is friend of class Ab. Class A is friend of class Cc. Class...
1 votes
1 votes
0 answers
3
sh!va asked Aug 9, 2016
1,018 views
Which of the following is (are) not recommended in a header file?a. Type definitions (typedefs)b. Class definitionsc. Function definitionsd. Template definitionsI. d only...
0 votes
0 votes
1 answer
4
sh!va asked Sep 2, 2016
358 views
Spot the features that are present in C++ not in Java:I. New operator II. Delete opeartor III. Objects stored in stack memory. IV . Objects stored in Heap memorya. ...