You are calling an object's constructor when you use the new keyword to create the object. Some objects (ok, most objects) have members that contain special information about that object. For example, a book object might have a member variable called title and one called author. Referring to a book is hard without knowing the title and the author, so this info is needed when we create a new book object. How are we going to pass that info to our book that we are creating? Using the constructor. We write a constructor for our book object that takes two
string arguments.
Let's further suppose that we want to subclass our book object to create an object called a programming book. ProgrammingBook objects will also have a member called language. When we need to create a new ProgrammingBook object we do it like this:
<PRE>
public class ProgrammingBook extends Book{
public ProgrammingBook(String author, String title, String language){
super(author, title);
this.language = language;
}
...
book bookOfTheMonth = new ProgrammingBook("Exploring Java", "Niemeyer & Peck", "Java");
</PRE>
In this case, we called super() to make use of our object's parent's constructor. Since Book already knows what to do with an author and a title, we just pass those on up to the Book constructor by calling super(). Then we make use of ProgrammingBook's member, language.
Does this help?
Bodie