Exercises

  1. What are the four attributes that distinguish object-oriented programming? What are some advantages and disadvantages of OOP?

  2. Give three examples of primitive types and three examples of predefined Java classes (i.e., object types).

  3. What is the default constructor, and when is it called? What is a no-arg constructor?

  4. Describe overriding, and write some code to show an example.

  5. Consider the following three related classes:

    class Mammal {}class Dog extends Mammal { }class Cat extends Mammal { }

    There are these variables of each class:

    Mammal m;Dog d = new Dog( );Cat c = new Cat( );

    Which of these statements will cause an error at compile time, and why? Which of these statements may cause an error at run-time, and why?

    m = d;       // 1. ...

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.