extends of the class with private constructor

后端 未结 3 1782
一生所求
一生所求 2020-11-30 05:39

Suppose we have the following code:

class Test {
    private Test() {
        System.out.println(\"test\");
    }

}

public class One extends Test {

    On         


        
3条回答
  •  醉梦人生
    2020-11-30 05:50

    Make the constructor of test non-private or move One into test.

    BTW, your sample code contains a few issues:

    • classes should be named title case (Test instead of test)
    • I'd suggest to make the One's constructor private unless it is called from a different class in the same package

提交回复
热议问题