11.1 | What are the common types of relationships among classes? Describe the graphical notations for modeling the relationships among classes. |
11.2 | What relationship is appropriate for the following classes? Draw the relationships using UML diagrams.
|
11.3 | Show the output of the following code: public class Test { public static void main(String[] args) { Rational r1 = new Rational( 1 , 3 ); Rational r2 = new Rational( 2 , 4 ); System.out.println(r1 + " + " + r2 + " = " + r1.add(r2)); System.out.println(r2 + " + " + r1 + " = " + r2.add(r1)); System.out.println(r1 + " - " + r2 + " = " + r1.subtract(r2)); System.out.println(r2 + " - " + r1 + " = " + r2.subtract(r1)); System.out.println(r1 + " * " + r2 + " = " + r1.multiply(r2)); System.out.println(r2 + " * " + r1 + " = " + r2.multiply(r1)); System.out.println(r1 + " / " + r2 + " = " + r1.divide(r2)); System.out.println(r2 + " / " + r1 + " = " + r2.divide(r1)); System.out.println(r1 + " = " + r1.doubleValue()); System.out.println(r2 + " = " + r2.doubleValue()); } } |
11.4 | What is wrong in the following code? Number r = new Rational(); System.out.println(r); System.out.println(r.doubleValue()); System.out.println(r.add( new Rational())); System.out.println((Rational)r.add( new Rational())); System.out.println(((Rational)r).add( new Rational())); |
11.5 | What is wrong in the following code? Number r = new Number(); System.out.println(r); |
11.6 | Is the following code correct?
|
11.7 | What is cohesion? Give examples of cohesive class design. |
11.8 | What is consistency? Give examples of nonconsistent class design. |
11.9 | What is encapsulation? What are the benefits of data field encapsulation? |
11.10 | When is it appropriate to use the protected modifier? |
11.11 | Which of the following is poor design?
|
11.12 | Which of the following is incorrect?
|