wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Calling constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calling constructor" Watch "Calling constructor" New topic
Author

Calling constructor

Supri dharshni
Greenhorn

Joined: Jul 14, 2009
Posts: 25
Hi,

Is there a way to call a constructor in a java class other than new,super keywords? I am asking for calling the constructor which is present in the same class.

Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

using this keyword


A.A.Anbarasu
Paul Beckett
Ranch Hand

Joined: Jun 14, 2008
Posts: 96
use "this":

Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Within the same class, the only way to call another constructor is from another constructor to hand over or augment to the initialization process.


JDBCSupport - An easy to use, light-weight JDBC framework -
Supri dharshni
Greenhorn

Joined: Jul 14, 2009
Posts: 25
Hi,

Sorry i forgot to mention that i have call the constructor of a class without using new,this,super keywords.For example,

public class A{

public A(){

System.out.println("Hello Constructor");
}

public static void main(String args[]){

}

}
Now i have to print "Hello Constructor" without using new,this,super keywords.Is it possible?
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

I still question why you would want to do this, but this will work for classes that have default constructors:



Sean


I love this place!
Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 188
Reflection would be another way but that's no topic for beginners.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling constructor
 
Similar Threads
Overridding query
Are Constructors Inherited/Overloaded/Overriden...
Default constructor
inheritence related questions in Java
inner classes