File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Importing a class

 
Sean Magee
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1272
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shakthi Anuradha
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok try this !
 
Shakthi Anuradha
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks! However, when I import it, it says

 
Natesh Kurup
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 119
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic