It looks like I got a bit confused in my core Java concepts .Please have a look below .
class A{
public void func1()
{
System.out.println("Hello A");
}
}
class B extends A{
public void func1(){
System.out.println("Hello B");
}
}
class C {
public static void main( String args[]) {
A myobj = new B();
myobj.func1();
}
}
As we know Webdriver is an interface & FirefoxDriver is the implementing class for Webdriver , so based on the above example is it right to assume that the statement : WebDriver driver=new FirefoxDriver()
is an example of late binding.
WebDriver driver=new FirefoxDriver()
is this compile-time or runtime binding?
That's compile-time binding to the class called FirefoxDriver
. It will use whatever FirefoxDriver
class is in the classpath. This is just about as compile-time as Java gets, as Java works from the classpath at compile-time and also at runtime.
Here's an example of runtime binding:
String driverName = /*...get the name from somewhere, like a properties file...*/;
WebDriver driver = Class.forName(driverName).newInstance();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.