• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling Classes and Methods  RSS feed

 
James Rennard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello! I'm working on an assignment and have constructed the following classes and methods, including an application to utilize the classes and methods. However, I get some strange lines printed when the application executes. I've debugged and can't seem to figure out what is going on. The lines that should read the invoiceNumber are showing as:

kft1task1.Invoice@48d593f7
kft1task1.Invoice@3de5627c
kft1task1.Invoice@1ea4daa3

Here is the application:


Here is the code for the classes / methods:


Thanks for your help!
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is now good time for you to understand the Object class and the methods that it has. Have a look at what a toString method means in Java. If you understand that, you will understand why you see those strange characters and you will be in a position to fix it so that you see what you wanted when you println your invoice objects.
 
James Rennard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Joe!

I thought about that and tried to add toString() by System.out.println(inv1.toString());, but it didn't do anything. It ran fine, but didn't output correctly. Am I missing something?
 
James Rennard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This seems to work well...I created a second constructor class and did all my string formation there:



Then, I just referenced that in my application:



Thoughts?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could override the toString() method in your class Invoice, then whenever you call it you'd get whatever you put in there, instead of something that looks like Invoice@4898ae
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!