Back To Java Classes Index
//program to demonstrate a class boxone which has a method that returns a value class boxone { private int width; private int depth; private int height; public void getdata() { width=10; depth=20; height=30; } public int volume() { int vol; vol=width*depth*height; return vol; } public void showdata() { System.out.println("width of box is "+ width); System.out.println("depth of box is " + depth); System.out.println("height of box is " + height); } }; public class classboxreturn { public static void main(String[] args) { int v; boxone ob=new boxone(); ob.getdata(); ob.showdata(); v= ob.volume(); System.out.println("Volume of box is " + v); } }