This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes  Instantiate a new object inside a class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " Instantiate a new object inside a class" Watch " Instantiate a new object inside a class" New topic

Instantiate a new object inside a class

akash gall

Joined: Feb 07, 2013
Posts: 3
Hi everyone,

I have this requirement where I need to instantiate a new object inside a class (from a jar), its like a jdbc connection manager.

From a testMethod() (which is static) I am calling my class (which contains a reference to this object). The class looks like this:

public class myClient {

public static MyClientManager manager = new MyClientManager();

public static String validateConnection() {
return null;

From testMethod, I am going myClient.validateConnection() and its always failing. If I remove this line (public static MyClientManager manager = new MyClientManager()) it works.

Please help.
Ishan Pandya
Ranch Hand

Joined: Feb 06, 2012
Posts: 225

What do you have in MyClientManager class?
Show the whole code. and where is "this" reference used?

Ivan Jozsef Balazs

Joined: May 22, 2012
Posts: 970
Maybe the constructor in the very line throws an exception preventing the class from being initialized.

I agree. Here's the link:
subject: Instantiate a new object inside a class
It's not a secret anymore!