Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error on inheritance example

Status
Not open for further replies.

DGA15

Programmer
Aug 19, 2000
40
US
Using JBuilder Personal 6.0.438.0 I get this error when trying the example on page 276 of "Thinking in Java" . The package is
saved as Detergent.jpx

"Cleanser.java": Error #: 901 : package Detergent stated in source C:\WINDOWS\jbproject\Detergent\src\Detergent\Cleanser.java
does not match directory . at line 1, column 9

Code is as follow:------------------------------------------------------------------------------------------------------------------

package detergent;


/**
* <p>Title: Detergent</p>
* <p>Description: Inheritance syntax and properties</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: Thinking in Java Pg# 276</p>
* @author WBG
* @version 1.0
*/

class Cleanser{ //super class from which class detergent inherits
private String s = new String(&quot;Cleanser&quot;);
public void append(String a) {s += a; }
public void dilute() { append(&quot;dilute()&quot;); }
public void apply() { append(&quot; apply()&quot;); }
public void scrub() { append(&quot; scrub()&quot;); }
public void print() { System.out.println(s); }
public static void main(String[] args) {
Cleanser x = new Cleanser();
x.dilute(); x.apply(); x.dilute(); x.scrub();
x.print();
}
}

public class Detergent extends Cleanser {
//change a method
public void scrub(){ //modifies the class Cleanser scrub method
append(&quot; Detergent.scrub()&quot;);
super.scrub(); // calls the base class method scrub
}
//Add methods to the interface of class Cleanser via inheritance
public void foam() { append(&quot; foam()&quot;); }
public static void main( String[] args) {
Detergent x = new Detergent();
x.dilute();
x.apply();
x.scrub();
x.foam();
x.print();
System.out.println(&quot;Testing Base class:&quot;);
Cleanser.main(args);
}
}

//end of code ----------------------------------------------------------------------------------------------------------
 
is the detergent package stored in exactly the same directory as the main java class you are running?
 
pipk,
Thanks, you identifed the problem. The main java class was in one directory and the package was in another. Thanks for the help.Billg in sunny Danville, CA
 
I'm getting that same error for my program and the main java file is in the same directory as the package.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top