I wrote a very simple program in java to get used with the use of static keyword.But i am getting the output as 0. I am not able to find the reason for that.I am a beginner in java .Can anyone please suggest a solution,also please do explain why such an problem was encountered …My code is as following :
public class Cube{
static int length;
static int breadth;
static int height;
public static int volume(final int i, final int j, final int k){
return length * breadth * height;
}
public static void main(final String args[]){
System.out
.println("volume of the cube is : " + Cube.volume(10, 20, 30));
}
}
intfields,staticor not, are initialized as0.You should multiply your operands (
i * j * k) or assign to your staticintfields.