This program copiles okay but gives no output

Write your question here.
Can someone make me understand why this program gives on output?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  Put the code you need help with here.
package Lists;

//Let's look at another possible implementation of the singly linked list.
//Note that this implementation is a singly linked list with a dummy head.
//We use nested class for the implementation.
public class SimpleList {
  private Node head = new Node(null, null); // dummy head
  private int size;

  public void addFirst(Object object) {
    head.next = new Node(object, head.next);
    size++;
  }

  public void addLast(Object object) {
	  // here I don't need a tail reference
    Node temp = head;
    while(temp.next != null)
      temp = temp.next;

   temp.next = new Node(object, null);
   size++;
  }

  public Object first() {
    if (size == 0) throw new IllegalStateException("the list is empty");
    return head.next.object;
  }

  public boolean isEmpty() {
    return (size == 0);
  }

  public Object removeFirst() {
    if (size == 0) throw new IllegalStateException("the list is empty");

    Object object = head.next.object;
    head.next = head.next.next;
    size--;
    return object;
  }

  public int size() {
    return size;
  }

  private static class Node {
// the Node class is defined within the SimpleList class
    Object object;
    Node next;

    Node(Object object, Node next) {
       this.object = object;
       this.next = next;
    }
  }
  public static void main(String[] args) {
	  SimpleList simplelist = new SimpleList();
	  simplelist.addFirst(new Integer(56));
	  System.out.println(simplelist);
  }
}

//Important: Inserting a node into or deleting a node from a linked list follows a strict sequence of steps.
//Changing the order of the steps in the sequence would lead to incorrect results.
 

When I run it I get this output:

Lists.SimpleList@1db9742
Last edited on
What compiler did you use to compile this program? It is JAVA but not C++...
I use eclipse.
It is correct, if you use the object name as a parameter of the System.out.println(...) function, you will see something like you had as an output - the name of the class of which the object is an instance, @ character, and the unsigned hexadecimal representation of the hash code of the object.
What did you want to see instead of this?
I only added 1 element in the list (56)
I expected to see it displayed when I run the program.
Then make this:
System.out.println(simplelist.first());
Thank you skaa. it worked fine. You are my star!!!
Topic archived. No new replies allowed.