java program for box using constructor
//program for box using constructor
import java.io.*;
import java.util.*;
class MyBox{
double length;
double breadth;
MyBox(double l,double b){
length=l;
breadth=b;
}
double vol(){
return length * breadth;
}
}
class Box{
public static void main(String args[]){
MyBox rectangle=new MyBox(10,20);
System.out.println("vol is "+rectangle.vol());
}
}
OUTPUT-
vol is 200.0
import java.io.*;
import java.util.*;
class MyBox{
double length;
double breadth;
MyBox(double l,double b){
length=l;
breadth=b;
}
double vol(){
return length * breadth;
}
}
class Box{
public static void main(String args[]){
MyBox rectangle=new MyBox(10,20);
System.out.println("vol is "+rectangle.vol());
}
}
OUTPUT-
vol is 200.0
Comments
Post a Comment