Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Anonmyous constructors

 
sanjana narayanan
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • 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
 
Shahid Mithani
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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%
 
jayakrishna marada
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic