Solved programming problem

Find A cubes Area by creating new class in Java.

Source code

Main Class:

 

package cube;

 

 

public class CubeTest 

{  

   public static void main(String[] args) 

   {

       Cube C = new Cube(5); ///creat an cube object and pass the side value

      // C.side=5; we can also save the value of side like this

       C.volume(); ///for calculating the volume call this method

   }

    

}

 

Cube Class:

 

package cube;

 

public class Cube {

 

    public int side;

    

    public Cube(int a) //CONSTRUCTOR

    {

        side = a;

    }

    

    void volume()

    {

        double  v = Math.pow(side,3); 

        System.out.println("Volume: "+v);

       

    }

 

}

Output

volume: 125.0

Join the discussion

Add your comment