-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
  • 11,641
  • 10
  • 42
  • 69
Psl
  • 3,602
  • 13
  • 43
  • 78

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,314
  • 2
  • 25
  • 40
1

Simply call FirefoxPhDriver drv = FirefoxPhDriver.newInstance(ingrdients)

Jens
  • 63,364
  • 15
  • 92
  • 104
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,495
  • 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.

JonasCz
  • 11,660
  • 6
  • 43
  • 64