Function behave like a servant for programmer.

A servant have a name,

A servant do something (What his master told him)

Servant may require tools(e.g Vacuum Cleaner to clean room)

Servant give result

int ted(int a, int b){

// do something interesting than this

int c = a+b;

return c;


Here the whole code act like a servant, and His name is ted. He require two things, after doing so logic he gave a return/reply to who ever called him.

Lets do our work done with help of this code.

we want to add to number 10, 20 and print the result on console

class A{
public static void main(String[] args){


Image by Artworkids from Pixabay

Scroll to top