Write a program in java using constuctor

Write a program in java using constuctor


class Box
   {
         double length,hight,depth;
     
      Box (double l,double h,double d) 
                 {
                     length=l; hight=h; depth=d;
                    }
                double volume()
                   {
             return(length*hight*depth);
     }
             }
class BoxDemo2
      {
        public static void main(String  []args)
           {
            double ans;
             Box b1=new Box(2.0,3.8,4.5);
             ans=b1.volume ();
             System.out.println("volume of  box is" + ans);
          }
     }

Comments

Popular posts from this blog

Write a java program to calculate gross salary & net salary taking the following data

WAP a program that illustrates interface inheritance. Create two interface p1 and p2 . create Interface p which extends p1 and p2 and then create interface p12 which extends p12. Each interface declare one constants and one method. Create class Q which implements p12 and define all the methods of interface which displays value of constants

Example of abstract class