my dog learned polymorphism*
The moose likes Beginning Java and the fly likes package access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package access" Watch "package access" New topic
Author

package access

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
I have a java class protect declared in default package
provided by javaruntime system.Now, i want to use this
protect class in another package named p1.How
can i do it.?
In default Package:
class protect{ protected int i=100;}
In package p1;
class sub extends protect{
public static void main(String s)
{ System.out.println(new sub().i);}
}
when i compile sub using
javac -d . sub.java // error as p1.protect not found.
Thanks!
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
You need to import class that are not in the same package as you are. Including those in the default package.
change to
package p1;
import protect;
class sub extends protect{
public static void main(String s)
{
System.out.println(new sub().i);}
}


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks! carl.That worked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package access
 
Similar Threads
access violation with a protected
Help on Packages!!
how to make two classes in a packahe where one class extends the other
Access modifier question...
Marcus Green - Exam 2 - Question 9