Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7582951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:33:47+00:00 2026-05-30T18:33:47+00:00

java.util.Queue<TreeNode> queue = new java.util.LinkedList<TreeNode>(); LinkedList implements Queue. Shouldn’t Queue be on the right

  • 0
java.util.Queue<TreeNode> queue = new java.util.LinkedList<TreeNode>();

LinkedList implements Queue. Shouldn’t Queue be on the right side of the above statement and LinkedList the left?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:33:48+00:00Added an answer on May 30, 2026 at 6:33 pm

    In Java, you can assign a value to a variable of the same type or a more general type. In your example, new LinkedList<TreeNode>() is a value. Since LinkedList implements Queue, it’s more specific than Queue. i.e. A LinkedList is a Queue.

    For instance, all three of these are valid

    Object o = new LinkedList<TreeNode>();
    Queue<TreeNode> queue = new LinkedList<TreeNode>();
    LinkedList<TreeNode> list = new LinkedList<TreeNode>();
    

    But you can’t write any of these because they’re incorrect assignment.

    LinkedList<TreeNode> o = new Object();
    LinkedList<TreeNode> queue = new Queue<TreeNode>();
    

    P.S. the second one in that example is also invalid because Queue is an interface, and you can’t instantiate (new) an interface because it’s not a concrete type

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

java.util.Date date = new java.util.Date(); java.sql.Date today = new java.sql.Date(date.getTime()); //2012-03-23 java.sql.Time time =
import java.util.*; import java.io.*; public String recToString (boolean format) { Date date = new
Here is a java code for breadth-first travel: void breadthFirstNonRecursive(){ Queue<Node> queue = new
Here is a snippet of the code- import java.util.concurrent.LinkedBlockingQueue def main(args:Array[String]) { val queue=new
I want to use java.util.ConcurrentLinkedQueue as a non-durable queue for a Servlet. Here's the
import java.util.Scanner; public class smth { Scanner input = new Scanner(System.in); int array[]={}; }
I was looking at the source of Java 1.6's Java.Util.ArrayDeque (a queue implementation) and
Why, oh why doesn't java.util.concurrent provide a queue length indicators for its ExecutorService s?
I am looking for a WorkQueue API offering the following features: java.util.Queue compatible offers
java.util.PriorityQueue allows a Comparator to be passed at construction time. When inserting elements, they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.