- #1
Live4eva_2
- 28
- 0
Hi,
I have 4 classes:Person,Date,Address,AddressBook.
I want to create an array of address book objects.(ive never created an object array though).
What I have done is created Person,Date and Address classes.Lastly,my Address class
has a default constructor that looks something like this:
public class AddressBook
{
private static int noOfEntries = 0;
private static AddressBook[] entries = new AddressBook[500];
This is the first time I've used constructors within another constructor.That seems to work fine though.As you can see I got stuck trying to reference the object that will be constructed.I tried using the keyword "this" but that doesn't seem to work.I just want to stick the object in the array at the position specified by noOfEntries.Can someone please help me out??
There is another small problem too though,usually I override the method toString() in my
classes in order to print it's data members.In this case though,I'm not sure how/where to define toString().
I have 4 classes:Person,Date,Address,AddressBook.
I want to create an array of address book objects.(ive never created an object array though).
What I have done is created Person,Date and Address classes.Lastly,my Address class
has a default constructor that looks something like this:
public class AddressBook
{
private static int noOfEntries = 0;
private static AddressBook[] entries = new AddressBook[500];
public Address()
{
Person temp = new Person();
Date aDate = new Date();
Address anAddress = new Address();
entries[noOfEntries] = ...
}
}{
Person temp = new Person();
Date aDate = new Date();
Address anAddress = new Address();
entries[noOfEntries] = ...
}
This is the first time I've used constructors within another constructor.That seems to work fine though.As you can see I got stuck trying to reference the object that will be constructed.I tried using the keyword "this" but that doesn't seem to work.I just want to stick the object in the array at the position specified by noOfEntries.Can someone please help me out??
There is another small problem too though,usually I override the method toString() in my
classes in order to print it's data members.In this case though,I'm not sure how/where to define toString().