aspose file tools*
The moose likes Beginning Java and the fly likes What is it called when you instantiate an object within a method's (  )? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is it called when you instantiate an object within a method Watch "What is it called when you instantiate an object within a method New topic
Author

What is it called when you instantiate an object within a method's ( )?

John Quach
Ranch Hand

Joined: Sep 28, 2011
Posts: 50
Here is the code. In the Slideshow class, the init() has JApplet and its object in the ( ). I didn't know you can instantiate inside the ( ).
What kind of technique is that?



John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
JApplet app refers to a reference of JApplet class. This is just a parameter of the method as you see in any other methods. The app variable is similar to the name variable below.



Instead of a String reference, you are passing a JApplet reference as an input argument to the method init() in the SlideShow class.

This method is called from the SlideShowMain class using the code -

So the object that is currently referenced in the SlideShowMain class is passed as the argument to init() method in the SlideShow class. And since SlideShowMain extends JApplet, a JApplet reference can refer to SlideShowMain object.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Do you really mean instantiate inside the ()? Or do you mean refer to?
Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 561
I assume he's referring to line 71:

Does that technique have a name?


Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Greg Brannon wrote: . . . Does that technique have a name?
I think it’s called using an anonymous object.
 
Don't get me started about those stupid light bulbs.
 
subject: What is it called when you instantiate an object within a method's ( )?