Exercises

  1. Distinguish between class and object, member and field, primitive type and class type.

  2. Write a sample program that demonstrates the compiler will not let you access a private member from another class, but that you can write a public accessor function to set the value of a private field. (Compile the first part, compile and run the second part.)

  3. Write a class with a static block, some constructors, and instance initializers that print out the order in which these are executed.

  4. Describe why a setSomething() method is often given protected visibility.

Get Just Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.