• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

package declaration

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to make one package of my own classes that i have made
i know that classes of package are in one directory
and i saw syntax package name (that u want to give )
i know this much ;

now i m making one new class
and than i want to import all the classes that i have made earlier
by using package name ; one answer might be put all the classes tht u have made in the same directory
than how can i import classes by package name
;
my question is how can i make package of classes
suppose i have 5 classes
a
b
c
d
e
how can i put these classes in one package whose name is p
and
now im making one new class z and now i want to use those classes(a,b,c,d,e)
that i have put in package p how can i import ?

i think that u can understand what i want to say ;
i have already declared that how much knowledge i have about package
im totally confused whether anyone can understand what i want to say :

if anyone can understand what i want to ask
please reply
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Java in General (Beginner).
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import p.*;

//or import each one:

import p.a;
import p.b;
import p.c;
import p.d;
import p.e;

public class Z {
}
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
you should define the package statement in a first executable line of the class file. If u have all classes in a single file then u should declared like below
package p;
class a{}
class b{}
.....
class f{}
and all the class are should be placed in a folder p. or if u have individual files od each of class u should place the package p statement in every class file.

If u want to import all the class in your file then u include following any one of the lines.
import p.*; //It import all the class availabe in package p;
(or)
import p.a;
import p.b;
...
import p.e; // It import specified package class only.
class z {} // Declaration of class Z

I hope it will be useful to u. If u have any more dubts reply me.

Regards
Raghu

Cheers!!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic