jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes call second constructor? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "call second constructor?" Watch "call second constructor?" New topic

call second constructor?

N. Gonzalez

Joined: Jul 17, 2005
Posts: 29
My program currently does not increment for each new student object created although this was defined in a larger constructor in the Student class (that calls upon a smaller constructor that generates a student id that should increment for each new student).

I'm uncertain of how to go about accomplishing this.
Should I be creating a whole set of Student objects again, now using the second constructor, because the contstructor I called for the Student object array didn't take the student id as an input parameter?

I barely understand what I'm doing and I've been at this all day...any hints or guidance is appreciated.

N. Gonzalez

Joined: Jul 17, 2005
Posts: 29
I also tried this and it didn't work...

Need some direction, please...
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33132

These two lines are giving you the problem. For each object, you set the id to 1000 and then increment it by one. But since this happens for each student, you never get anywhere with the incrementing.

You really want this to be two variables. One to keep track of the current maximum assigned student id and one to keep track of the student id for that particular student. Tip: Think about which one of these needs to be static.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
N. Gonzalez

Joined: Jul 17, 2005
Posts: 29
So are you saying one will be a static class variable and one and instance variable?

I guess I'm confused with the instructions that the constructor should generate the student id.
I agree. Here's the link: http://aspose.com/file-tools
subject: call second constructor?
It's not a secret anymore!