|
-
March 1st, 2000, 12:05 PM
#1
Instanciate an Object
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.
-
March 1st, 2000, 07:28 PM
#2
Re: Instanciate an Object
import Person;
.........
Person p = new Person();
.......
your Person.class should be placed in the working directory.
good luck
Alfred Wu
-
March 3rd, 2000, 04:42 AM
#3
Re: Instanciate an Object
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
-
March 3rd, 2000, 05:35 AM
#4
Re: Instanciate an Object
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|