Invoking a Function in Java


☞A process of using a method in a program is called as invoking a method or calling a method.

Example

class Square{
    
    int side;
    
    void input(int s){
        side=s;
    }
    
    void area() {
        System.out.println("Area is "+(side*side));
    }
    
    void perimeter() {
        System.out.println("Perimeter is "+(4*side));
    }
    
    public static void main(String[] args) {
        Square obj= new Square();
        
        obj.input(5);   //calling a input() function
        obj.area();     //calling a area() function
        obj.perimeter();//calling a perimeter() function

    }
    
}

Output

Area is 25
Perimeter is 20