• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with null answers  RSS feed

 
Shio Nakashima
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again.

I have a further problem, which I require your help on please.

I have now set one object to reference another (with help from Craig) e.g

but the output I get when I enter System.out.println(T222.toString()); (which should output the details of the couse, or System.out.println(T222.studentCode); is null, instead of the studentCode.

Can anyone see what I am doing wrong.

I also have a question to ask:

what does zero-arg constructor mean?



I think I understand what constructors are for but should I have put the default studentCodes in here (eg studentCodes = t222 ..

Any and all help appreciated. I hope this makes sense.
 
Craig Tyler
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you want to do is the following:



That accesses the string named studentCode in the Course object named t222. Remember, everything is case sensitive so T222 is not the same as t222.

As for the no-arg constructor, you can create default values as you thought.



You can also make more specific constructors so that you could pass the information like studentCode and name when you first create the object if you want.
 
Shio Nakashima
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once again Craig, I thank you for your help.

One question to clear up though (if you don't mind), I thought when you assign one object to reference another (t222.studentCode = "T222") both have the same information. why is this not so in this case?
 
Craig Tyler
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I follow you in this case. When you do (t222.studentCode = "T222"), you are essentially giving a reference to t222.studentCode that points to a String object containing "T222". You're giving that reference to the studentCode member of the t222 object you made earlier. I'm not sure if this answers your question or not.
 
Shio Nakashima
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does and I thank you for taking the time to explain it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!