wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Using class of the package in other classes in the 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 "Using class of the package in other classes in the package?" Watch "Using class of the package in other classes in the package?" New topic
Author

Using class of the package in other classes in the package?

Sloan Bowman
Ranch Hand

Joined: Jan 21, 2003
Posts: 107
Is it possible to use objects from classes with the same package you are creating? I keep getting errors. Below is an example
package com.test;
import com.test.*;
public class Test
{
public Test()
{}
public static void main(String[] args)
{
Users u = new Users();
u.setUsername("SloanB");
String name = u.getUsername();
System.out.println(name);
}
}

Second class
package com.test;
public class Users
{
private String username;
private String password;
public Users()
{
}
public void setUsername(String name)
{
this.username = name;
}
public String getUsername()
{
return(this.username);
}
} // end class

Thanks for the help as usual
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
Q)Is it possible to use objects from classes with the same package you are creating?
A)Yes it is possible.
There is no need of import class of same package (It is just a optional).
The problem what I guess you are facing is incorrect way of calling the cass.
Follow this step to make your code work.
1)set the classpath. i.e, set classpath=%classpath%;c:\example;
Here replace c:\example with the folder name where your com folder is located.
2)Then execute the main method with the fully qualified name. That is
Java com.test.Test

-arun


Sharing is learning
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using class of the package in other classes in the package?
 
Similar Threads
Implementing HttpSession in the Spring MVC
JPA Composite PK with FK problem
can anybody answer my question
Boolean and boolean problems in JavaBeans
Find the data type of a variable