This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Anonmyous constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Anonmyous constructors" Watch "Anonmyous constructors" New topic
Author

Anonmyous constructors

sanjana narayanan
Ranch Hand

Joined: Nov 25, 2003
Posts: 142
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

Joined: Dec 04, 2003
Posts: 8
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

Joined: Dec 08, 2003
Posts: 1
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Anonmyous constructors
 
Similar Threads
Anonmyous class
Anonmyous class
Constructors for Interface
Constructor
cannot be instantiated