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

  • Home
  • SEARCH
  • 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 8933699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:36:31+00:00 2026-06-15T09:36:31+00:00

I am trying to write a recursive method inside a searchTree class, and for

  • 0

I am trying to write a recursive method inside a searchTree class, and for some reason, the methods are looking outside the class in the interface for the definition of the method rather than looking at themselves. Here are some snippets of the code:

in Main class:

    public class BinarySearchTree<T extends Comparable<T>> implements BinarySearchTreeInterface1<T>, BinarySearchTreeInterface2<T>{`

recursive method within Main:

    public int getHeight(){
        if (isEmpty()){
            return 0;
        }else{
            int height = 1 + Math.max(this.getLeftSubTree().getHeight(),
                                      this.getRightSubTree().getHeight());
            return height;
        }
   }`

As you can see I have two interface classes. The error underlines getHeight() and states:

cannot find symbol
symbol: method getHeight()
location: interface BinarySearchTreeInterface1<T>
where T is a type-variable:
 T extends Comparable<T> declared in class BinarySearchTree

I have 5 recursive methods that were shown in the Interface2 file and all of them are getting this same erorr. Thanks for any assistance.

Update: I am hesitant to post the Interface classes as they are from a university class and I don’t wish to upset the instructor. The ironic thing is, the non-recursive methods work just fine. Here is a small part of what the Interface2 file shows:

public interface BinarySearchTreeInterface2<T>{

    public int getNumberOfNodes();

    public int getHeight();
  • 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-06-15T09:36:33+00:00Added an answer on June 15, 2026 at 9:36 am

    It seems that getLeftSubTree() returns a BinarySearchTreeInterface1<T>. But getHeight() is defined in BinarySearchTreeInterface2<T>, so the method getHeight() can’t be called on the result of getLeftSubTree().

    You might be able to get the program compile by overriding the getLeftSubTree() method like this:

    public BinarySearchTree<T> getLeftSubTree() {
        ...
    }
    

    Of course, the same must be done with getRightSubTree().

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

Sidebar

Related Questions

I am trying to write a recursive function within a class, but have some
I'm trying to write a recursive function that would get some string, as well
I'm trying to write a recursive method which may take a array/value as input
I'm trying to write a recursive jQuery statement that grabs some data and populates
I'm trying to write a Python class that acts like some sort of datastore.
I am trying to write a recursive method that searches through a list of
I've been trying to write a recursive string method for a binary search tree
I am trying to write a recursive method to print n number of asteriks
I'm trying to write very simple recursive method, but can't make it work. I
I'm trying to write a recursive fun in an Erlang shell, but I keep

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.