in this code:
public class Main{
private void method()
{
System.out.println("inside method");
}
public static void main(String[] args) {
Main obj = new Main();
obj.method();
}
}
Why can we access a private method using an object from the class when we are in the class and we cannot do it outside the class? (I mean, what is the logical reason?)
Another case: the method mainis static, so why is there no compiler error complaining about "accessing the non-stationary method from the static method"?
source
share