CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 1999
    Location
    Germany
    Posts
    37

    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.


  2. #2
    Join Date
    Dec 1999
    Location
    Chonghe, Taipei County, Taiwan, R.O.C.
    Posts
    231

    Re: Instanciate an Object

    import Person;
    .........
    Person p = new Person();
    .......
    your Person.class should be placed in the working directory.
    good luck
    Alfred Wu


  3. #3
    Join Date
    May 1999
    Location
    Germany
    Posts
    37

    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


  4. #4
    Join Date
    Dec 1999
    Location
    Chonghe, Taipei County, Taiwan, R.O.C.
    Posts
    231

    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
  •  





Click Here to Expand Forum to Full Width

Featured