How to Call a Method in Another Class of the Same Package

Access to method of another class in the same package is not possible

This code is not valid Java, you cannot call a method from the body of a class, a method call has to be part of some kind of initializer (such as a static field initializer or static block) or a method.

public class test {
csvReader.updateCSV(...);
}

Can I call a static method of one class in another class under same package?

You can call a method with the syntax ClassName.methodName() if the method is declared static, eg

class ClassName {
static void methodName() {
//...//
}
}

More info about static class members can be found in the Java Tutorials.



Related Topics



Leave a reply



Submit