• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

doubt related to packages

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic