• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

private access through reflection

 
venkat ga
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anybody explain below program. private means only with in the scope. but outside we can't access.
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting topic, and *maybe* useful for the SCJP, but I think this will cause more confusion than help in this, SCJP, forum so I'm moving it to the General forum.

Bert
 
Henry Wong
author
Marshal
Pie
Posts: 21496
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
venkat ga wrote:
Can anybody please explain below program. private means only with in the scope. but outside we can't access.


See these lines....



It means turn off access checks. For Applets, or anything else with a security manager, this call will generate a security exception. For everything else, it will allow a program to access all fields (regardless of access permission) of an object.

Henry
 
venkat ga
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Henry,

I changed in the same code flags true to false,



I got exception as

NoNameTitle:NoNameAuthor:100
Exception in thread "main" java.lang.IllegalAccessException: Class simple.Demo can not access a member of class simple.Book with modifiers "private"


Turn off access checks : It means internally JVM treats that, all are public ?
So we can access any where irrespective of access specifiers once we turn off access checks.



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic