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 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 Android Security Essentials Live Lessons this week in the Android 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: 24183
    
  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: 24183
    
  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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IS THERE ANY WAY TO CALL A NON-STATIC METHOD TO STATIC METHOD
 
Similar Threads
Please help clarify this!
Static method and classes
properties values not being set
best way to handle database connection
Static method and classes