java - How to override a method which is used in the parent constructor? -


i'm having design problem don't know how overcome in java. want override method called parent constructor. here simple example of problem:

public class parent {     public parent(){         a();     }      public void a() {         // code         return;     } }  public class child extends parent {     public child() {        super();     }      public void a() {        super.a();        // more code        return;     } } 

i know child class wont initialized until parent constructed therefore childs a() method wont called. correct design overcome problem?

the child override called - child constructor won't have executed yet, unless it's designed invoked on partially initialized object, have problem. best approach not call virtual methods in contructors. is problem. in control of both classes? can redesign avoid problem in first place?


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -