Exercises
-
What are the four attributes that distinguish object-oriented programming? What are some advantages and disadvantages of OOP?
-
Give three examples of primitive types and three examples of predefined Java classes (i.e., object types).
-
What is the default constructor, and when is it called? What is a no-arg constructor?
-
Describe overriding, and write some code to show an example.
-
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.