Post date: Jan 30, 2016 5:11:1 AM
Chapter 8: Polymorphism and Abstract Classes
8.1 Polymorphism
Recommended Self-Test exercises: ALL!
Lab Exercise:
Test your classes with the following TestShape class:
// A test driver program for Shape and its subclasses public class TestShape { public static void main(String[] args) { Shape s1 = new Rectangle("red", 4, 5); System.out.println(s1); System.out.println("Area is " + s1.getArea()); Shape s2 = new Triangle("blue", 4, 5); System.out.println(s2); System.out.println("Area is " + s2.getArea()); Shape s3 = new Shape("green"); System.out.println(s3); System.out.println("Area is " + s3.getArea()); } }
Source: Java Programming Tutorial