java - Is there a difference between calling a method from within a class' method code or on an instance of the class? -
i have piece of code here , i'm not sure couple of commands do:
//this bit body of main method //lots of stuff omitted project frame = new project(); frame.creategui(); private void creategui() { setdefaultcloseoperation(exit_on_close); panel = new jpanel(); }
so when frame.creategui();
called, happens 2 commands in creategui();
? they
setdefaultcloseoperation(exit_on_close); panel = new jpanel();
or
frame.setdefaultcloseoperation(exit_on_close); frame.panel = new jpanel();
or else entirely? i'm quite new @ java, started year 12 computer science year, bit ahead of class.
thanks time!
every non static method in java has hidden parameter called this
. it's value object in front of dot in invocation. inside body of methods, invocations of other methods implicitly have this.
in front of them. use of variables, if cannot resolved locally. if this
reference explicit, method this:
private void creategui(project this) { this.setdefaultcloseoperation(this, exit_on_close); this.panel = new jpanel(); }
in invocation of creategui
in main method, happening this:
frame.creategui(frame);
when running creategui
this
reference reference frame
.
Comments
Post a Comment