All About Class IllegalAccessException in Java



IllegalAccessException is thrown when an application tries instantiate a class and tries to  load a class through its String name using the any of the following methods:
  1. forName(), this method is defined in Class Class.
  2. findSystemClass(),this method is defined in Class ClassLoader.
  3. loadClass(),this method is defined in Class ClassLoader.
but the currently executing method does not have access to the definition of the specified class,because the class is not public or may be in another package or may not have a public constructor.So basically we tried to call a method that has restricted access.
An instance of this class can also be thrown when an application tries to create an instance of a class using the newInstance() method in class Class but the current method does not have access to the appropriate zero argument constructor. Chain method calling may also suffer from this exception.
The structure of the class is defined as below:


public class java.lang.IllegalAccessException extends java.lang.Exception{
//constructor
public IllegalAccessException();
//constructs an empty IllegalAccessException object that is an object with no message specified.
public IllegalAccessException(String message);
//constructs an IllegalAccessException object with the message specified.

}
 

All About Class IllegalAccessException in Java All About Class IllegalAccessException in Java Reviewed by Animesh Chatterjee on September 17, 2018 Rating: 5

No comments:

Powered by Blogger.