Mark, Here is the source. Customer.java compiles while
CustomerTest.java doesn't. Thanks
//Customer.java
public class Customer{
private String fname, lname;
public static void main(String[] args){
}
public Customer(String firstname, String lastname){
this.fname=firstname;
this.lname=lastname;
}
}
//CustomerTest.java
public class CustomerTest extends Customer{
public static void main(String[] args){
Customer p=new Customer("fname","lname");
}
}
> > Hi Mark,
> > Yes File1.java compiles. Only File2.java throws an error saying-
[quoted text clipped - 31 lines]
>
> Mark
Mark Thomas - 17 Apr 2006 12:06 GMT
> Mark, Here is the source. Customer.java compiles while
> CustomerTest.java doesn't. Thanks
[quoted text clipped - 54 lines]
>>
>> Mark
Ah! You misquoted the error message - it doesn't say "Cannot find
symbol File1 (or Customer)" rather "cannot find symbol : constructor
Customer()". Your CustomerTest class doesn't define a constructor -
when that happens, Java provides you with a default no-argument
constructor. Any constructor always calls the corresponding constructor
in its superclass, in this case that would be a no-argument constructor
in Customer - and you haven't got one! Hence the error message. Note
that as soon as you provide a constructor for a class, as you have for
Customer, you lose the default constructor.
Here the is no reason for CustomerTest to extend Customer. It is not a
subclass (there is no way that a CustomerTest is-a-kind-of Customer),
but a class that uses Customer. So remove the 'extends Customer' and
all will be well.
Always give the actual error message that is causing you problems -
having read it first!
Mark
as4532@drexel.edu - 17 Apr 2006 12:38 GMT
Thanks for the reply Mark. I removed the word "extends". Now this is
the error message i am getting:
CustomerTest.java:11: cannot find symbol
symbol: class Customer
Location: class CustomerTest
Customer p=new Customer("fname","lname")
What i need to know is that how can i use the class which is in a
different .java file but same directory as my current .java file.
> > Mark, Here is the source. Customer.java compiles while
> > CustomerTest.java doesn't. Thanks
[quoted text clipped - 74 lines]
>
> Mark
Venkatesh - 17 Apr 2006 14:26 GMT
U need to either set your classpath properly: Include "current
directory" in your classpath by saying
SET CLASSPATH=%CLASSPATH%;. in windows
or
CLASSPATH=$CLASSPATH:. in unix machines
Then run javac
Otherwise, u can compile both java files together, use
javac Customer.java CustomerTest.java
as4532@drexel.edu - 17 Apr 2006 14:46 GMT
Hi Venkatesh,
Thanks a lot for the help. Classpath was the issue.. when i
compiled the 2 classes together it works fine. Thanks again!
A
> U need to either set your classpath properly: Include "current
> directory" in your classpath by saying
[quoted text clipped - 6 lines]
> Otherwise, u can compile both java files together, use
> javac Customer.java CustomerTest.java