Question: **QUESTION**
How come this code here:
`Object y=x.remove();` removes the object from the queue?
Isn't this just a variable assignment. Why does it run the code, when we are not calling it? Does variable deceleration call the methods as well? 

```html
Queue<Integer> x = new LinkedList<Integer>();
    x.add(5);
    x.add(7)
    Object y=x.remove(); //<------THIS
    x.add(4)
    System.out.println(x.element());
```

Answer: 
Well from the [documentation of the method](https://docs.oracle.com/javase/7/docs/api/java/util/Queue.html#remove()) itself its very clear what it does there:

```
/**
 * Retrieves and removes the head of this queue.  This method differs
 * from {@link #poll poll} only in that it throws an exception if this
 * queue is empty.
 *
 * @return the head of this queue
 * @throws NoSuchElementException if this queue is empty
 */
E remove();

```

Dry run your code to find the details:

> 
> 
> ```
> x.add(5): --> 5
> x.add(7); --> 5,7
> Object y=x.remove(); --> 7, y=5
> x.add(4); --> 7,4
> System.out.println(x.element()); --> Prints 7 (head without removing this time)
> 
> ```
> 
>
You are calling method of a queue class(.remove()). And this method remove the first element of the queue and return it. You can use peek method ( Object y=x.peek(); ), if you want to check the first element of the queue without removing it.