-1

So I designed this class in Java and am trying to test it. When I run the test file, it prints a memory address instead of the actual name. Any ideas?
Here is the class:

 public class Card{
 private String name; 

 public Card() { 
      name = " "; 
 }
 public Card(String n) { 
      name = n; 
 } 
 public String getName() { 
      return name;
 }
 public boolean isExpired() { 
      return false;
 }
 public String format() { 
      return "Card holder: " + name; 
 } 
}

Here is the test file:

 import java.io.IOException;

 public class Lab12Test { 
 public static void main (String [] args) throws IOException { 

      Card q = new Card("John");
      System.out.println("Card Class: " + "\n");
      System.out.println(q); 

 }
}
  • Override toString() method – Kartic May 03 '15 at 18:15
  • You are missing `toString` method in `card` class. You can override in `Card` class E.g. `@Override public String toString() { return "Card{" + "name='" + name + '\'' + '}'; }` – sol4me May 03 '15 at 18:16

1 Answers1

0

Define toString() method in your class

Germann Arlington
  • 3,315
  • 2
  • 17
  • 19