Shape.java
public interface Shape {
String draw();
void calcSomething();
}
Square.java
public class Square implements Shape {
@Override
public String draw() {
return "SQUARE";
}
@Override
public void calcSomething() {
}
}
When I implement an interface, the method that I implemented must be public.
I want to make draw() public method but calcSomething() private or protected.
I've gone through Interfaces in Java: cannot make implemented methods protected or private . And there no straight way to do this
So instead of using interface I'm planning to use abstract class
Shape.java using abstract class
public abstract class Shape {
abstract public String draw();
abstract protected void calcSomething();
}
Square.java that implements Shape abstract class
public class Square extends Shape {
@Override
public String draw() {
return "SQUARE";
}
@Override
protected void calcSomething() {
}
}
Which one should I choose. Should I use interface and make the calcSomething() public or Should I use abstract class and make the calcSomething() protected