Answer to Question #145302 in Java | JSP | JSF for Nhlanhla

Question #145302
Briefly explain what a method is and describe the three main parts of a
method.

By making use of an example, show how method overloading takes place. Also
indicate how overloaded methods can be called from mainline logic.
1
Expert's answer
2020-11-19T08:31:34-0500

Methods in Java are a complete sequence of actions (instructions) aimed at solving a particular problem. In fact, these are functions (aka procedures, subroutines) of earlier, non-OOP languages. Only these functions are members of classes and, to distinguish them from ordinary functions, according to the terminology of object-oriented programming, are called methods. Methods are always defined inside classes.

Overloading means making the same method have different behaviour depending on its arguments. We can create another add method with three int arguments which will return sum of first two arguments minus third argument.

int add(int a, int b, int c)
{
return ((a+b)-c);
}

Now when we call add method, its behaviour is dictated by the parameters passed during its call.

...
x = add(10,20); // x = 30
y = add(10,20,30); // y = 0

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