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 7623255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:39:39+00:00 2026-05-31T04:39:39+00:00

Here I am trying to practice making binary trees so that I can do

  • 0

Here I am trying to practice making binary trees so that I can do different operations with them.

import java.util.*;
import java.lang.*;


public class Main {

public static void main(String[] args) {

}
}

//Building Binary Trees
class bTree {

static class Node { //remember to initilize a root

    String value;
    Node left, right;

    Node(String value, Node left, Node right) {
        this.value = value;
        this.left = left;
        this.right = right;
    }
    Node(String value) //THIS IS A SIBLING CONSTRUCTOR
    {
        this(value, null, null);
    }

    Node root = new Node("ROOT");
    Node lefty = new Node("LEFT0");
    Node righty = new Node("RIGHT0");
    root.left = lefty;
    root.right = righty;
}
Node root = null;
}

Why am I getting the error: Identifier expected at the root.left and root.right assignment?

Thanks!

  • 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-31T04:39:41+00:00Added an answer on May 31, 2026 at 4:39 am

    The assignment statements

    root.left = lefty;
    root.right = righty;
    

    are not allowed on the class level. You can achieve the effect you want changing this line

    Node root = new Node("ROOT");
    

    to this

    Node root = new Node("ROOT", lefty, righty);
    

    which takes advantage of your three-argument constructor.

    However, you may want to reconsider the placement of root, lefty and righty. They are probably intended in the bTree class. Also, there is a convention that encourages naming class capitalizing the first letter of each word, e.g. BinaryTree.

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

Sidebar

Related Questions

I'm trying to build an app (for practice) that uses CoreData and different view
RSpec newbie here. I'm trying to test my models, which have methods that uses
I'm trying to practice making a simple video phone app so I'm trying to
I'm trying to make an app that can work on multiple devices. Desktop, Mobile
I'm trying to wrap my head around something; maybe someone here can point me
Programming Student here...trying to work on a project but I'm stuck. The project is
I am going nuts here trying to resolve a cascading update/delete issue :-) I
I know of the ||= operator, but don't think it'll help me here...trying to
Noob dumb question, no doubt -- but here it is: Trying to tutorialize myself
After my last, failed, attempt at asking a question here I'm trying a more

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.