Why do we create a reference variable of type WebDriver, not the actual browser type?

Why do we create a reference variable of type WebDriver, not the actual browser type?

Hi Brett,

We create a reference variable to WebDriver type because we could use the same WebDriver variable to hold the object of any browser such as the ChromeDriver, IEDriver, or SafariDriver, etc. We follow this approach as it can work with any browser instance.

WebDriver driver = new FirefoxDriver();

WebDriver driver = new ChromeDriver()

The following method is also correct but it will work only with the Firefox.

FirefoxDriver driver = new FirefoxDriver();