Object-Oriented Design with UML and Java public Rectangle(double upperLeftX, double upperLeftY, double width, double height) { this(new Point(upperLeftX, upperLeftY), width, height); } public double getPerimeter() { return 2 * (theWidth + theHeight); } public double getArea() { return theWidth * theHeight; } // —– Attributes —————-private Point theUpperLeft; private double theWidth; private double theHeight; } The sample application code is given in program G.4. Here, we create instances of the Rectangle and Triangle classes and interrogate each for their perimeter and area values. Program G.4 public class Main { public static void main(String[ ] args) { Rectangle rect = new Rectangle(0.0, 4.0, 4.0, 4.0); // square 4 x 4 Triangle tri = new Triangle(0.0, 0.0, 3.0, 0.0, 3.0, 4.0); // 3-4-5 right triangle ConsoleIO.out.println( Rectangle: + rect.getPerimeter() + , +rect.getArea()); ConsoleIO.out.println( Triangle: + tri.getPerimeter() + , +tri.getArea()); } } G.4 Exercises 1. Carefully distinguish between the terms interface, abstract class and concrete class. 2. Carefully distinguish between the Java keywords extends and implements, ensuring that you are clear where they are used. 3. Carefully distinguish between the terms superclass and subclass. How may a subclass differ from its superclass? How much commonality is there? Describe what is meant by substitutability when discussing superclass and subclass. 4. What do you understand by the terms redefinition and the polymorphic effect? Explain their value to OO development. 5. What feature does a subclass constructor method use to initialize inherited attributes?
For high quality java hosting services please check tomcat web hosting website.
This entry was posted
on Monday, January 5th, 2009 at 12:07 am and is filed under java jsp tomcat.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.