Java-Class with Methods

Class with Methods

A method is a block of statements that has a name and can be executed by calling it from some other place in your program. The general form is :

The return_type is the type of the value that is returned by the method to its caller. If no value is returned by a method, then the keyword void should be specified in the place of type. The method_name is the name assigned to the method by the user. It shall be any valid identifier. The body of the method contains a set of statements. The statements in a method describe the operations that are performed by the method. Once we define a method, we shall invoke it any number of times. To use a method, we have to invoke it by specifying its name.

Program

rererer

Program Source

class Area{
 
    int length;
    int hight;
    int width;
 
    void areaVolume()
    {
        System.out.println("Area volume is : "+length*hight*width);
    }
}

public class Javaapp {

    public static void main(String[] args) {
     
        Area a1 = new Area();
        a1.length = 100;
        a1.hight  = 25;
        a1.width  = 75;
        a1.areaVolume();
    }
}

Leave a Comment