• Post Reply Bookmark Topic Watch Topic
  • New Topic

print edge object  RSS feed

 
Mona Alsh
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I'm trying to implement a graph and here I got the Edge and the Vertex classes

Vertex:



Edge class:


My problem is that when I print the edge it prints the memory address although I override the method toString() !!!

When I run this line of code

Edge e = new Edge(3,2,2.2);
System.out.println(e);

I got this result:
Edge@1aa8c488

but printing the vertex works fine

really appreciate your help!
Thanks,
Mona
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mona Alsh wrote:although I override the method toString() !!!

Are you sure about that ? Take a closer look.

It's always a good idea to put an @Override annotation on any method you think is overriding another method. Then the compiler will tell you when you get it wrong.
 
Mona Alsh
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:
Mona Alsh wrote:although I override the method toString() !!!

Are you sure about that ? Take a closer look.

It's always a good idea to put an @Override annotation on any method you think is overriding another method. Then the compiler will tell you when you get it wrong.


Wow thank you very much!
I got it !That's was very helpful
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!