Wednesday, December 23, 2015

Method with Parameter in java

Method with Parameter in java
package javaapplication27;


public class MethodWithParameter {
    double width;
    double height;
    double depth;
   
   
     public double volume(){
return width * height * depth;

                }
    void setDim(double w,double h,double d){
    width=w;
    height=h;
    depth=d;
    }
   
    public static void main(String[] args) {
        MethodWithParameter obj= new MethodWithParameter();
       
        double vol;
       
        obj.setDim(5, 10, 15);
       vol=obj.volume();
       
        System.out.println("Volume is "+vol);
    }
}

 Output:
run:
Volume is 750.0

0 comments:

Post a Comment