I wonder if a class having the main method can extend an other class. When I tried, there was an error showing
the constructor is not visible
The solution was to change "protected" to "public". However, I know if a class inherits from an other class, it can use protected methods. Here, this didn't work. Does anyone know what's wrong with this?
package second;
import first.Accumulator;
public class Saving extends Accumulator {
protected Saving() {
super()
}
protected Saving(int num) {
super(num);
}
protected void addAmount(int amount) {
add(amount);
}
protected void showAmount() {
show();
}
}
package third;
import second.Saving;
public class SavingTest extends Saving {
public static void main(String[] args) {
Saving saving = new Saving(100);
saving.addAmount(100);
saving.showAmount();
}
}
The result: The Constructor Saving(int) is not visible.