12.11. Key Terms

 
[Page 393 ( continued )]

Review Questions

Section 11.3 Discovering Relationships Among Objects

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.
  • Company and Employee

  • Course and Faculty

  • Student and Person

  • House and Window

  • Account and Savings Account

  • The JOptionPane class and the String class

  • The Loan class and the Date class ( §7.15)

Section 11.5 The Rational Class

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)); 

[Page 394]
 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?

Section 11.6 Class Design Guidelines

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?
  • A data field is derived from other data fields in the same class.

  • A method must be invoked after/before invoking another method in the same class.

  • A method is an instance method, but it does not reference any instance data fields or invoke instance methods .

  • A parameter is passed from a constructor to initialize a static data field.

11.12 Which of the following is incorrect?
  • A static method may reference instance data fields or invoke instance methods.

  • An instance method may reference static data fields or invoke static methods.

  • A constructor may be static.

  • A constructor may be private.

  • A constructor may invoke a static method.

  • A constructor may invoke an overloaded constructor.

  • A constructor invokes its superclass no-arg constructor by default if it does not invoke an overloaded constructor or its superclass's constructor.


    [Page 395]
  • An abstract class contains constructors.

  • The constructors in an abstract class are public.

  • The constructors in an abstract class are private.

  • You may declare a final abstract class.

  • An interface may contain constructors.

  • An interface may contain instance data fields.

  • An interface may contain static methods.

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net