This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Anonmyous constructors  RSS feed

 
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!