OOP Part 1, Exercises

A

Create a class with a default constructor and prints a message. Create one or more objects of the new class. Add an overloaded constructor that takes a String argument. The topic is constructors in Java.

B

Create an array of String objects and assign a string to each element. Print out the strings using a for loop. The topics are arrays and strings.

C

Create a class Dog that has an overloaded method named bark(). This method should be overloaded for all the primitive types. Write a main method that calls all the overloaded bark() methods. The topic is overloading methods.

D

Create a class with a finalize() method that prints a message. Create a main() method that creates objects of the new class. Run the program and try to explain the behavior of the program. The topic is the special method finalize.

Extra Assignments

E1

Discuss the problems involved in scheduling when to run the garbage collection.

E2

Demonstrate that the Java garbage collector finds and frees memory taken up by a network of objects (object pointing to other objects and so on) that can no longer be reached from the current program.