Methods
youtube:Zooming | https://github.com/Soba-Arjun/
• It is a collection of statements that perform some specific task and return the
result to the caller.
• A method can perform some specific task without returning anything.
• Methods allow us to reuse the code without retyping the code.
• In Java, every method must be part of some class.
Method Declaration
youtube:Zooming | https://github.com/Soba-Arjun/
• Data type values can return.
• Void can’t return.
youtube:Zooming | https://github.com/Soba-Arjun/
Calling a Method
 Method to be invoked when,
 Complete statement in the method
 It reaches a return statement
 Throws an exception
 Based on access modifier, method can
be accessed.
class Addition {
int sum = 0;
public int addTwoInt(int a, int b){
sum = a + b;
return sum;
}
}
class GFG {
public static void main (String[] args){
Addition add = new Addition();
int s = add.addTwoInt(1,2);
System.out.println(s);
}
}

Java Methods

  • 2.
    Methods youtube:Zooming | https://github.com/Soba-Arjun/ •It is a collection of statements that perform some specific task and return the result to the caller. • A method can perform some specific task without returning anything. • Methods allow us to reuse the code without retyping the code. • In Java, every method must be part of some class.
  • 3.
    Method Declaration youtube:Zooming |https://github.com/Soba-Arjun/ • Data type values can return. • Void can’t return.
  • 4.
    youtube:Zooming | https://github.com/Soba-Arjun/ Callinga Method  Method to be invoked when,  Complete statement in the method  It reaches a return statement  Throws an exception  Based on access modifier, method can be accessed. class Addition { int sum = 0; public int addTwoInt(int a, int b){ sum = a + b; return sum; } } class GFG { public static void main (String[] args){ Addition add = new Addition(); int s = add.addTwoInt(1,2); System.out.println(s); } }