This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes default package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "default package" Watch "default package" New topic
Author

default package

pras
Ranch Hand

Joined: Apr 04, 2007
Posts: 188
/********** first program*********************/

class Abc {

}


/*********second program**********************/
package a;
class Xyz {

}

/***question*************/
can i create a Xyz instance in Abc?
if yes how?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41089
    
  43
Yes, you can, in the same way you instantiate all objects: "new Xyz()"

Since Xyz is not in the same package as Abc, you will need to add an "import" statement to your code.

You will also need to make the class public, i.e. "public class Xyz".
[ July 30, 2007: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: default package
 
Similar Threads
Thread Question - Examlab Practice Exam 1
How to extend or onstantiate classes in same package
Compile with the package statement
is it dynamic binding?
K&B: Has-a relationship