• Post Reply Bookmark Topic Watch Topic
  • New Topic

doubt related to packages  RSS feed

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


hi ranch,

i have some doubt in java.

1. suppose i write two classes in two different files in the same directory, how can i call one class from the other?

2. i tried the concept of package.

i created source file page.java in the current working directory. then i put another source file check.java in a directory called pro. Now pro is in the current directory.

in beginning of check.java i said package pro;
i compiled the file in pro.
i went to the home directory and in the file page.java i said import pro;

its showing compilation error. but this is how i read in books.

now how to do it in java?

try to answer.

jose.

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this

import pro.test3;
public class test1
{

public static void main(String a[])
{

test3 t=new test3();
System.out.println(t.get());

}
}

this is in pro package
package pro;
public class test3
{

public String get()
{
return "in pro";

}

}


access modifier should be public
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"jose jose",
Welcome to the JavaRanch!

We're pretty light on rules, but one we take very seriously is one about display names. You can read about it here but basically we require your display name to be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and fix your display name, since accounts with invalid display names get deleted, often without warning

thanks,
Dave
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!