debugging - Java Flow of execution - overridden method gets executed first than the constructor -


i have following code, in same java file.

import javax.swing.swingutilities; import java.io.file;  public class mainclass2{    public static void main(string[] args){        swingutilities.invokelater(new runnable(){              public void run() {                  javax.swing.jfilechooser jfc = new myfilechooser();                      file file = jfc.getselectedfile();              }        });    } }  class myfilechooser extends javax.swing.jfilechooser{     public myfilechooser(){         system.out.println("constructor call");     }     @override     public java.io.file getselectedfile(){         system.out.println("call getselectedfile");         return null;     } } 

when run it, output gives me

call getselectedfile

constructor call

call getselectedfile

shouldn't output be

constructor call

call getselectedfile

i'm using java 5.

myfilechooser's constructor equivalent to:

public myfilechooser() {     super(); // ***     system.out.println("constructor call"); } 

the first call getselectedfile() made myfilechooser's base class constructor, invoked implicitly @ point marked *** above, before system.out.println("constructor call").

here stack trace:

myfilechooser.getselectedfile() line: 16     aquafilechooserui.installcomponents(jfilechooser) line: 1436     aquafilechooserui.installui(jcomponent) line: 122    myfilechooser(jcomponent).setui(componentui) line: 670   myfilechooser(jfilechooser).updateui() line: 1798    myfilechooser(jfilechooser).setup(filesystemview) line: 360  myfilechooser(jfilechooser).<init>(file, filesystemview) line: 333   myfilechooser(jfilechooser).<init>() line: 286   myfilechooser.<init>() line: 11  

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

post - imageshack API cURL -

dataset - MPAndroidchart returning no chart Data available -