• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package access

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);}
}
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! carl.That worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic