/* Demo #1
This program aims at:
- Showing the overall structure of a Java application program
- Defining class
- Differentiating between class variables and instance variables
- Differentiating between class methods and instance methods
- Defining constructors and to show that constructors can be overloaded
- Creating instances (objects) of a class
- Invoking class methods as well as instance methods
*/
public class CreateSphere
{
public static void main(String[] args)
{
Sphere ball, globe;
System.out.println("Number of objects created so far = " + Geometry.Sphere.getCount());
System.out.println();
ball = new Sphere(4.0, 0.0, 0.0, 0.0);
System.out.println("Number of objects = " + ball.getCount());
globe = new Sphere(12., 1.0, 1.0, 1.0);
System.out.println("Number of objects = " + globe.getCount());
Sphere thirdBall = new Sphere(100, 20.0, 30.0);
System.out.println("Number of objects = " + thirdBall.getCount());
Sphere oddBall = new Sphere(); System.out.println("Number of objects = " + oddBall.getCount());
Sphere copyThirdBall = new Sphere(thirdBall);
System.out.println("Number of objects = " + copyThirdBall.getCount());
Sphere enlargeThirdBall = new Sphere(thirdBall, 10);
System.out.println("Number of objects = " + enlargeThirdBall.getCount());
System.out.println();
System.out.println("ball volume = " + ball.volume());
System.out.println("globe volume = " + globe.volume());
System.out.println("thirdBall volume = " + thirdBall.volume());
System.out.println("oddBall volume = " + oddBall.volume());
System.out.println("copyThirdBall volume = " + copyThirdBall.volume());
System.out.println("enlargeThirdBall volume = " + enlargeThirdBall.volume());
}
}
Go Back