Created
October 23, 2017 18:00
-
-
Save javamultiplex/c496661143ef871c48539a392b4c4070 to your computer and use it in GitHub Desktop.
Example of IllegalAccessException present in java.lang package.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javamultiplex.java.lang.exceptions; | |
/** | |
* @author Rohit Agarwal | |
* @version 1.0 | |
* @category java.lang/Exception | |
* @since JDK 1.0 | |
*/ | |
class Test { | |
private Test() { | |
} | |
} | |
public class IllegalAccessExceptionDemo { | |
public static void main(String[] args) { | |
try { | |
/* | |
* IllegalAccessException will be thrown because we are trying to | |
* create an instance of Test class that has private no argument | |
* constructor. | |
* | |
*/ | |
Test test = Test.class.newInstance(); | |
System.out.println(test); | |
} catch (InstantiationException | IllegalAccessException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment