| Author |
Importing a class
|
Sean Magee
Ranch Hand
Joined: Aug 23, 2004
Posts: 69
|
|
I am trying to figure out hot to make, and then import my own class. Any help would be appreciated. So here is my code on attempting to make my own constructor. Am I starting off on the right foot? Can anyone help me on where I go from here? I want to eventually be able to import this, and use Anyone?
|
 |
Mike Gershman
Ranch Hand
Joined: Mar 13, 2004
Posts: 1272
|
|
You're OK until Instead of "int = 0;", use "age = A;" You will also want to include getAge() and setAge() methods like your getName() and setName() methods. Then you're golden.
|
Mike Gershman
SCJP 1.4, SCWCD in process
|
 |
Shakthi Anuradha
Greenhorn
Joined: Nov 16, 2004
Posts: 5
|
|
|
Ok try this !
|
 |
Shakthi Anuradha
Greenhorn
Joined: Nov 16, 2004
Posts: 5
|
|
Ok try this ! use like this public class Person{ private String name; private int age; void setName (String N){ name = N; } String getName() { return name; } Person() { name=""; } Person (String N, int A) { name = N; int = 0; } } ........................................................................... than whan u need this class or constructor no matter what the class use import Person;
|
 |
Shakthi Anuradha
Greenhorn
Joined: Nov 16, 2004
Posts: 5
|
|
Ok try this ! use like this public class Person{ private String name; private int age; void setName (String N){ name = N; } String getName() { return name; } Person() { name=""; } Person (String N, int A) { name = N; age = 0; } } ........................................................................... than whan u need this class or constructor no matter what the class use import Person;
|
 |
Sean Magee
Ranch Hand
Joined: Aug 23, 2004
Posts: 69
|
|
Ok, thanks! However, when I import it, it says
|
 |
Natesh Kurup
Greenhorn
Joined: Nov 23, 2004
Posts: 19
|
|
hi, If the Person class is not in the same package as the other class, You need to place Person class within a package and import the package. Also the package needs to be in classpath Regards Natesh Calling class
|
 |
louise rochford
Ranch Hand
Joined: Apr 04, 2002
Posts: 119
|
|
Hi Sean, Did you get this sorted out? If not, could you post the full code for Person and the class that uses it (sean?) - including the package & import statements at the top of the class. The error looks really weird - like it thinks that the class is called Person. rather than Person - maybe you compiled it with javac Person..java by mistake? (Though I'm not sure that javac would let you do this). Also, if sean is a class, it should start with a capital letter. Package names should be all lower case. Regards, Louise
|
 |
 |
|
|
subject: Importing a class
|
|
|