• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Importing a class

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok try this !
 
Shakthi Anuradha
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks! However, when I import it, it says

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Liar, liar, pants on fire! refreshing plug:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic