Exercises


Note

The solutions to these exercises are in Appendix B.

  1. Suppose package superpack contains subpackage subpack. Suppose a source file contains the following line:

    import superpack.*;

    Will this line import classes in subpack? Write code to support your answer.

  2. Create a class that illegally tries to read a private variable of another class. What is the point of this exercise?

  3. Create a class that illegally tries to call a default-access method of another class.

  4. Create a class that illegally tries to write a protected variable of another class.

  5. True or false: If a class has at least one abstract method, the class must be abstract. Write code to support your answer.

  6. True or false: If a class is abstract, it must have at least one abstract method. Write code to support your answer.

  7. Write an application that tries to construct an instance of an abstract class. Can you compile the application? Can you execute it?




Ground-Up Java
Ground-Up Java
ISBN: 0782141900
EAN: 2147483647
Year: 2005
Pages: 157
Authors: Philip Heller

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