You are on page 1of 1

// Class and Object initialization showing the Object Oriented concepts in Java

class Cube {

int length = 10;


int breadth = 10;
int height = 10;
public static int numOfCubes = 2; // static variable

public static int getNoOfCubes() //static method


{
return numOfCubes;
}
public Cube()
{
numOfCubes++;
}
}

public class CubeStaticTest {

public static void main(String args[])


{
System.out.println("Number of Cube objects = " +
Cube.numOfCubes);
System.out.println("Number of Cube objects = " +
Cube.getNoOfCubes());
}
}

You might also like