Back To Java Classes Index
//program to create a class box with data members (width,depth and height) and member functions (getdata,showdata and volume)(volume member function calculates the volume of the box ) class box { private int width; private int depth; private int height; public void getdata() { width=10; depth=20; height=30; } public void volume() { int vol; vol=width*depth*height; System.out.println("volume of box is " + 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 classbox { public static void main(String[] args) { box ob=new box(); ob.getdata(); ob.showdata(); ob.volume(); } }