Why can't a Java class be both abstract and final

前端 未结 6 1482

Suppose I\'ve a utility class which contains only static methods and variables. e.g:

public abstract final class StringUtils
{
    public static final String         


        
6条回答
  •  自闭症患者
    2020-12-16 23:48

    A final class can't be extended, an abstract class needs to be extended in order to be instantiated. Therefore, a final abstract class would be a logical contradiction.

    If your class just have static methods, maybe you should just hide its constructor, by defining it as private.-

    private StringUtils() {
    }
    

提交回复
热议问题