Can you access the private method from outside the class?
1759
01-May-2015
Updated on 18-Sep-2020
Anonymous User
01-May-2015You 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