aspose file tools*
The moose likes Beginning Java and the fly likes IS THERE ANY WAY TO CALL A NON-STATIC METHOD TO STATIC METHOD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "IS THERE ANY WAY TO CALL A NON-STATIC METHOD TO STATIC METHOD" Watch "IS THERE ANY WAY TO CALL A NON-STATIC METHOD TO STATIC METHOD" New topic
Author

IS THERE ANY WAY TO CALL A NON-STATIC METHOD TO STATIC METHOD

arullis michaelraj
Greenhorn

Joined: Jun 20, 2005
Posts: 5
i have one method like.


public static connection getConnection()throws SQLException
{
return getConnection(POOL_NAME);
}

It is one file like DBDelegate.java
i have another method in another file ArConnectionPool.java like

public Connection getConnection(String aPoolNameStr) throwsArReportException
{
}



Here How can i call non-static method through static method?

Is there any possible way?

if it is,please tell me.

I am expecting your reply.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Hi,

WELCOME TO JAVARANCH!

WAIT, LET ME PRESS THE Caps Lock key... there, that's better.

Note that we have many different forums here. You picked the "Java News" forum, which is for industry-related announcements, not for Java questions. I'll move this thread to the Java in General (Beginner) forum for you, and I'll meet you over there...


[Jess in Action][AskingGoodQuestions]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

For a static method to call a non-static method, the static method needs access to an instance of the class with the non-static method; i.e.,

ArConnectionPool pool = new ArConnectionPool();
pool.getConnection("foo");

Although based on the name of the class, it seems unlikely that you'll want to create an instance of a connection pool each time you access it -- most likely, a single instance will be held in a static variable somewhere.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: IS THERE ANY WAY TO CALL A NON-STATIC METHOD TO STATIC METHOD