In an assignment, I have to use four different files in a single program. I know doing so has something to do with inheritance (which we're studying now), but I don't understand how to write each file to use the others. How do I use multiple files in this single program?

The assignment reads like this:

* create four distinct .java files:
o Person.java
o HeadofHousehold.java (extends Person)
o Dependent.java (extends Person)
o NeighborhoodCensus.java (which will contain the program's main() method)
* use an array of Dependents in capturing input and producing output

As in several earlier assignments, your goal is to create a program that gathers census information from possibly several households, until the user indicates that he or she wishes to stop. At the end of the process of gathering information for each family, that family's data will be reported in this sequence:

* all summary household data as reported in previous assignments, such as the level of family income
* the name, age, gender, and marital status of the HeadofHousehold (only one per family)
* the name, age, gender and marital status of each Dependent in the family

Files are not inherited. Classes are inherited.
Just create all the files in the same folder, they'll all be in the same(default) package visible to each other. You shall use "extends" keyword in class definitions. At the end just compile the class that contains the main() method, then java compiler will automatically compile others as well (or you can compile each one by one).

Sounds like you might want to go back and not sleep through class next time. In the meantime, try this link.

multiple files in this single program?

import java.awt.*;

an example of using annother "file" (what you seem to be calling classes) in a different program

I don't understand how to write each file to use the others

public Class1 extends Class2

That is the syntax, if you are indeed studying inheritance then you would probably know that, and you would know how to progress. Unless of course you couldn't be bothered to turn up to your classes. In which case there is ample resources on the internet (I've never been taught or "studied" java and i know how to use inhertance because i could be bothered to read about it and practice and ask resonable questions) It is extreemly lazy of you to not even be bothered to type it into google and take a look at the first tutorial you find - but then you are lazy for not going to your classes in the first place. /rant

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.