File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "What is package level restriction? " Watch "What is package level restriction? " New topic

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

Joined: Jul 08, 2003
Posts: 24195

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

[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?
I agree. Here's the link:
subject: What is package level restriction?
It's not a secret anymore!