-1

public class SLList { public IntNode first;//create a 64 bits space for first as a type of IntNode

public SLList(int x) {
    first = new IntNode(x, null);
} 

public void addFirst(int x) {
    first = new IntNode(x, first);
}

public static void main(String[] args) {
    SLList L = new SLList(10);
    L.addFirst(10);
    System.out.println(L);
}

}

Yulong Wu
  • 37
  • 1
  • 7

1 Answers1

0

System.out.println(L) will call the toString() method on the parameter (L in this case). Since L is a class rather than a String, the default toString() method prints ClassName@HashCode. If you want a textual representation of the contents in L you'll want to override the toString() method:

public class SLList {
    ...
    @Override
    public String toString() {
        return "Overridden toString()";
    }
    ...

Then System.out.println(L) will print Overridden toString().

Matt U
  • 4,970
  • 9
  • 28