Click to See Complete Forum and Search --> : Instanciate an Object


Askia Boly
March 1st, 2000, 11:05 AM
hello,
I would like a litle enlightment about instaanciation in Java.
For example I have the following code creating an object "Person"


public class Person {

public String name ;
public String dept ;


public Person() {
this.name = "" ;
this.dept = "General" ;
}

}




And yet I would like to instanciate this Object "Person" within another code.
Please tell me how this works in java and what should I take care off when instantiating an Object in another source code.
Thanks.

kib63613
March 1st, 2000, 06:28 PM
import Person;
.........
Person p = new Person();
.......
your Person.class should be placed in the working directory.
good luck
Alfred Wu

Askia Boly
March 3rd, 2000, 03:42 AM
Hello Alfred,
Thanks for the reply.
However it still doesn't work that way to. I am receiving a message "Class Person not found in import".
The Person class is in the same directory as the other sources files which are going to instanciate it in there bodies.
Do you have any other view of what the problem could be ?
Sincerely.
Askia

kib63613
March 3rd, 2000, 04:35 AM
To tell the truth, I never encounter this kind of strange problem. I guess that it
might be the several cases :
1. the class name and the file name do not match.
2. setting the classpath overwrites the orignal classpath.
3. the classpath do not set current directory. classpath=.; So the current dirctory is not searched.
4. the class file name imported is not the same as the real file name in the directory.
5.the file is not in the specified directory
The whole thing that I can guess is like above. If it does not work. Sorry..........
I can not help you :)
good luck
Alfred Wu