• 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

Anonmyous constructors

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I know that the constructors for anonmyous class is provided implicitly.
My question is
when these constructors take parameters, how are these parameters related to the enclosing /super class. Pl explain it with some code samples.
-Sanajan
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you use default constructor to create the anonymous class, you basically call the default (no param) constructor of the overridden class.
You can also create the anonymous class by calling the overloaded constructor in the overridden class. You simply give the parameters in the constructor when you create the anonymous class.
For example...


Shahid Mithani
SCJP 96%
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sanjana narayanan:
Hi,
Depending on the number and type and ordering of the parameters it will look for the same type of constructor in the super class.
ex:
abstract class A {
A(int h , int j)
{
}
public abstract void callme();
}
class B
{
public A returnA()
{
return new A(5,6){
public void callme()
{
....
}
};
}
}
so the anonymous class calls the A(int , int) super class constructor.
Jay k


I know that the constructors for anonmyous class is provided implicitly.
My question is
when these constructors take parameters, how are these parameters related to the enclosing /super class. Pl explain it with some code samples.
-Sanajan

 
reply
    Bookmark Topic Watch Topic
  • New Topic