Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i use a class from a different file in java?

Tags:

java

Am new at Java and this is what am attempting to do;

I Have two files located on this folder on a windows machine;

d:\programs\sims\javasim\src\com\jsim\
Person.java
Building.java

On my Building.java am making use of class Person located in file Person.java i.e.

package com.jsim;
ArrayList<Person> personList = new ArrayList<Person>();

Am compiling the files from this folder

d:\programs\sims\javasim\src

But when i try to compile Building.Java, the compiler tells me

d:\programs\sims\src\javac com/jsim/Building.java

com\jsim\Building.java:10: cannot find symbol
symbol  : class Person
location: class com.jsim.Building
        private ArrayList<Person>personList = new ArrayList<Person>();
                          ^

How can i make Building.java know about class Person in file Person.java?

Gath

like image 708
gath Avatar asked Apr 21 '11 15:04

gath


Video Answer


1 Answers

execute javac *.java or javac Person.java Building.java or javac Building.java Person.java to compile your classes.

Seems like Person.java is not compiled before compiling Building.java file.

Building needs Person's class file for compiling instead of .java file.

like image 165
user2340671 Avatar answered Oct 01 '22 19:10

user2340671