java - Is there any point in an abstract class having public constructor instead of protected one? -


Since an abstract class can not be done immediately, and because protected members are always sub- Appears in sections, it appears that it does not matter whether its consultants are public or protected .

Is there an example where there might be a protected one compared to a public manufacturer? I usually like the most restrictive access level which is applicable.

No, there is no good reason to create a public constructor for an abstract class: The class can not instantiate within the class without subdividing, and the language is related to matters related to you.

Specifically, if you have an intangible class anonymously, which means that you are unable to provide your own constructor in the subclass, the language will be signed by the Protector of your abstract base class. Based on this one will provide one for you:

  abstract square fu {protected intestine x; Protected Foo (int x) {this.x = x;} public abstract zero times (); } Public static Zero main (string [] algos) {Foo foo = new Foo (123) {// & lt; & Lt; == This is because of the "compiler magic" public word bar () {System.out.println ("Hello" + x);}}; Foo.bar (); }  

In the above example, it seems that the protected creator of an abstract class is implemented, but that is not the way: the compiler will have your anonymous class * , What happens when you type new Foo (123)

* The default visibility is default Thanks, Pshemo, to open the error and to supply good.


Comments