Answer to Question #262284 in Java | JSP | JSF for ro212

Question #262284

 Different methods named sum need to be created in one class, explain what mechanism should be used. Then Illustrate with examples the different ways to achieve that.


1
Expert's answer
2021-11-07T10:15:22-0500

The mechanism used in this case is method overloading.

it can be achieved through the following:

a. Changing number of arguments

b. Changing the data type


Example

class Addition{  
  static int sum(int a,int b){
    return a+b;
  }  
//Changing number of arguments
   static int sum(int a,int b,int c){
      return a+b+c;
  } 
// Changing the data type
    static double sum(double a,double b,double c){
      return a+b+c;
  }          
}  

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS