• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
John Quach
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48374
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you really mean instantiate inside the ()? Or do you mean refer to?
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume he's referring to line 71:

Does that technique have a name?
 
Campbell Ritchie
Sheriff
Posts: 48374
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Brannon wrote: . . . Does that technique have a name?
I think it’s called using an anonymous object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic