Can you access the private method from outside the class?
Ask by Anonymous User
Updated 18 Sep 2020
You can call the private method from outside the class by changing the runtime behaviour of the class.
By the help of java.lang.Class class and java.lang.reflect.Method class, we can call private method from any other class.
Example:
A. java
public class A {private void message(){System.out.println("hello java"); }
}
Method.java
Output:hello java