oop - How to enforce constructor in Java -


is there way enforce specific constructor in java classes?

for example want classes inherit class have constructor -

public classname(string s1,string s2){....} 

i know should not avoided because can lead problems multiple inheritance. there way anyway?

there no facilities in java directly.

however, can enforced extent usin abstract method.

abstract class base {      base(string s1, string s2) {         init(s1, s2);     }      protected abstract void init(string s1, string s2); }  class myclass extends base {      // forced this.     myclass() {         super("one", "two");     }      // forced this.     @override     protected void init(string s1, string s2) {     }  } 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -