OOP Part 1, Exercises


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.


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.


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.


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


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


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.