I am little bit confused with reference variable and object in Java.Please explain below line
Queue<Node> q = new LinkedList<Node>();
LinkedList<Node> q = new LinkedList<Node>();
Now my question
- In first line, Why we are creating "q" variable of type Queue but and assigning object of type LinkedList?
- What we can and can't do with "q" if we will write above line as
LinkedList<Node> q = new LinkedList<Node>();
- When we will require 1st line over 2nd line.Please give me some example.