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)
}
2
  • Thanks. But this yielded another error message: The method sortSelection(int[], int) in the type Helpclass is not applicable for the arguments (CD[], int)
    – Kristian
    Commented Oct 21, 2011 at 18:52
  • Your CD class needs to implement the Comparable Interface.
    – Fault
    Commented Oct 21, 2011 at 19:00
1

you need to call the other class before using its method

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.