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("Cleanser"
public void append(String a) {s += a; }
public void dilute() { append("dilute()" }
public void apply() { append(" apply()" }
public void scrub() { append(" scrub()" }
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(" Detergent.scrub()"
super.scrub(); // calls the base class method scrub
}
//Add methods to the interface of class Cleanser via inheritance
public void foam() { append(" foam()" }
public static void main( String[] args) {
Detergent x = new Detergent();
x.dilute();
x.apply();
x.scrub();
x.foam();
x.print();
System.out.println("Testing Base class:"
Cleanser.main(args);
}
}
//end of code ----------------------------------------------------------------------------------------------------------
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("Cleanser"
public void append(String a) {s += a; }
public void dilute() { append("dilute()" }
public void apply() { append(" apply()" }
public void scrub() { append(" scrub()" }
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(" Detergent.scrub()"
super.scrub(); // calls the base class method scrub
}
//Add methods to the interface of class Cleanser via inheritance
public void foam() { append(" foam()" }
public static void main( String[] args) {
Detergent x = new Detergent();
x.dilute();
x.apply();
x.scrub();
x.foam();
x.print();
System.out.println("Testing Base class:"
Cleanser.main(args);
}
}
//end of code ----------------------------------------------------------------------------------------------------------