Answer the question
In order to leave comments, you need to log in
How to access a class method with the private static modifier from another class?
I have a conditional class A which has a private static method.
public class A{
public static void main(String[] args) {
String c = "abc";
int result = methodB(c);
}
private static int methodB(String c) {
/ * */
}
}
Answer the question
In order to leave comments, you need to log in
DeNissss4444 , you can (and should) test only what is "available to the world" from the class.
Private method tests are by definition unnecessary. Today there is a method, tomorrow it was removed, breaking the functionality into two parts. Or they changed the signature. Or ... in general, what's going on there "under the hood", in the privates of the class - it's only and exclusively for this class.
Only externally accessible methods matter.
Roughly speaking, if you have a public method for sorting an array with a sort() bubble, and the private method swap() is called in it, then you do not need to test whether the exchange works correctly. Test sorting. Because tomorrow you will rewrite sorting to something more kosher, and instead of swap() you will have some kind of join().
The only important thing is that sort() returns the correct value.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question