O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

Whether the Engine class is implemented as an inner class or a method-local inner class, the test code looks the same:

public static void main(String arg[]) {  double timeSec = 10.0;  int engineHorsePower = 246;  int vehicleWeightPounds = 4000;  Vehicle vehicle = new Vehicle(vehicleWeightPounds, engineHorsePower);  System.out.println("Vehicle speed (" + timeSec + " sec) = " +                      vehicle.getSpeedMph(timeSec) + " mph");}

If we run this program, we get the same output:

Now, let's assume we need to test different implementations of the getSpeedMph() method:

public double getSpeedMph(double timeSec){ return -1.0d; }

If this speed calculation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required