0

I have a sorting method created in a class separate from the class I am currently working in. The sorting method is a public static void method named:

public static void sortSelection(Comparable[] array, int n)

In the class where I currently work, entitled "Library", I wish to call upon this method as part of a different sorting method which I simply call "sort". So, I have written as follows:

public void sort() {
sortSelection(CDCollection, numberOfCDs)
}

where CDCollection is an array, and numberOfCDs is an integer. However, I get the error message:

"The method sortSelection(CD[], int) is undefined for the type Library"

If anyone knows whay may cause this error, I would greatly appreciate it!

2 Answers 2

3

You call a static method on a class by providing the class name. Something like this:

public void sort() {
    OtherClassName.sortSelection(CDCollection, numberOfCDs)
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. But this yielded another error message: The method sortSelection(int[], int) in the type Helpclass is not applicable for the arguments (CD[], int)
Your CD class needs to implement the Comparable Interface.
1

you need to call the other class before using its method

public void sort()
{
     ClassName.sortSelection(array, int);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.