*
The moose likes Java in General and the fly likes What is package level restriction? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "What is package level restriction? " Watch "What is package level restriction? " New topic
Author

What is package level restriction?

Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

Yesterday I was just to add a file in package which comes with java. Like java.lang
I wrote following code



and got following error when tried to run that class.




I want to know that how they achieved package level restriction? I know that some may feel this question absolute baseless because naming a package which is already there makes no sense. But i just want to know that what really happens and how they have done it? If someone can help me that will be very helpful to me.

Thanks a lot for reading this.


My Blog SCJP 5 SCWCD 5
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The stack trace makes it pretty clear that it's implemented by java.security.SecureClassLoader .


[Jess in Action][AskingGoodQuestions]
Peter Lawrey
Ranch Hand

Joined: Dec 21, 2008
Posts: 62
The Sun license agreement, which you agreed to when you downloaded Java states you cannot modify or add to standard packages such as java.* and javax.*, sun.* and com.sun.*

Solution: Use your own package.
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

Thanks Peter.

Have you gone through the whole agreement before accepting it?
 
Consider Paul's rocket mass heater.
 
subject: What is package level restriction?