Java Reference
In-Depth Information
33. val vehicle2 = new Bike(100)
34. val vehicle3 = new Batmobile(300)
35.
36. val vehicleList = List(vehicle1, vehicle2, vehicle3)
37. val fastestVehicle = vehicleList.maxBy(_.mph)
38.
39. printVehicle
40.
41. def printVehicle{
42. println ("speed of Bike : " + vehicle1.mph);
43. println ("speed of Car : " + vehicle2.mph);
44. println ("speed of Batmobile : " + vehicle3.mph);
45. println ("Fastest Vehicle : " + fastestVehicle.mph + " mph");
46.
47. }
48. }
49. }
When the previous code is compiled and executed, it produces the following result:
>scalac vehicle.scala
>scala Vehicle
speed of Bike : 200 mph
speed of Car : 100 mph
speed of Batmobile : 300 mph
Fastest Vehicle : 300 mph
Summary
This appendix introduced you to the basics of Scala. You learned three ways to interactively
execute Scala code as a script and as a compiled program. Then you learned how to use the Scala
collections library. Finally, you learned how to use traits and how to use a singleton object in an
application.
 
Search WWH ::




Custom Search