Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Jenya Mia
Added: Mar 19, 2019 12:32 PM
Views: 14
  1. SecurityManager securityManager=System.getSecurityManager();
  2.  
  3.    if(securityManager==null)
  4.  
  5.       System.out.println("security manager is not installed");]]></description>
  6.             <content><![CDATA[public class AccessibilityCheck {
  7. public static void main(String[] args) {
  8.    Class<Employee> c = Employee.class;
  9.    try {
  10.       Employee e = c.newInstance();
  11.       Field name = c.getDeclaredField("name");
  12.       Field doj = c.getDeclaredField("joinDate");
  13.       name.setAccessible(true);
  14.       doj.setAccessible(true);
  15.       System.out.println("Value of name: "+ name.get(e));
  16.       System.out.println("Value of joinDate: "
  17.          + name.get(e));
  18.       name.set(e, "Harry");
  19.       doj.set(e, new Date());
  20.       System.out.println("Changed value of name: "
  21.          + name.get(e));
  22.       System.out.println("Changed value of joinDate: "
  23.          + doj.get(e));
  24.  
  25.          System.out.println(ex.getMessage());
  26.       }
  27.    }
  28. }