• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?



 
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79412
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you really mean instantiate inside the ()? Or do you mean refer to?
 
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume he's referring to line 71:

Does that technique have a name?
 
Campbell Ritchie
Marshal
Posts: 79412
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Greg Brannon wrote: . . . Does that technique have a name?

I think it’s called using an anonymous object.
 
pie. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic