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

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -