-1

Here i have a class named FirefoxPhDriver

public class FirefoxPhDriver extends AbstractWebPhDriver {

    public static FirefoxPhDriver newInstance(
            PhDriverIngredients ingredients) {
        FirefoxPhDriver pd = new FirefoxPhDriver();

        if (pd.verify(ingredients)) {
            return pd;
        }

        return null;
    }
}

As i new to java am not sure how can i call this newInstance method in another class

i tried

FirefoxPhDriver drvr = new FirefoxPhDriver(ingrdients)

But am getting the constuctor FirefoxPhDriver is not visible

Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78
Psl
  • 3,830
  • 16
  • 46
  • 84

4 Answers4

4

It's just FirefoxPhDriver drvr = FirefoxPhDriver.newIstance(ingrdients).

(Because newInstance is a static method you don't need to create an instance of FirefoxPhDriver to access the method (so no new FirefoxPhDriver(...)).)

thomas.mc.work
  • 6,404
  • 2
  • 26
  • 41
1

Simply call FirefoxPhDriver drv = FirefoxPhDriver.newInstance(ingrdients)

Jens
  • 67,715
  • 15
  • 98
  • 113
1

You actually have no Constructor defined in your FirefoxPhDriver class, but the default Constructor.

But you have a Method defined

public static FirefoxPhDriver newInstance(PhDriverIngredients ingredients)

This method creates a new Instance of the FirefoxPhDriver class.

You can use it like that:

FirefoxPhDriver drvr = FirefoxPhDriver.newInstance(ingredients);
Community
  • 1
  • 1
B. Kemmer
  • 1,517
  • 1
  • 14
  • 32
0

newInstance() method is static method in FirefoxPhDriver class. We can call static members along with Classname.

Use this:

 FirefoxPhDriver.newInstance(ingrdients);

If you want to call methods from other class we should declare those methods as either public or protected or default. We cannot call Private members from other class.

Jonas Czech
  • 12,018
  • 6
  • 44
  • 65