I'm a newbie to Java. I came across these questions when I'm exploring the Java concepts.
Is the Upcasting and Polymorphism
are same? And I'm confused with these two terms.
interface IWebdriver{
void closeBrowser()
}
Public class ChromeDriver implements IWebdriver{
public void closeBrowser(){
//Implementation
}
}
Public class FirefoxDriver implements IWebdriver{
public void closeBrowser(){
//Implementation
}
}
Public class InternetExplorerDriver implements IWebdriver{
public void closeBrowser(){
//Implementation
}
}
Main(){
IWebdriver driver;
driver = new ChromeDriver(); // Polymorphism or Upcasting ??
driver = new FirefoxDriver(); // Polymorphism or Upcasting ??
driver = new InternetExplorerDriver(); Polymorphism or Upcasting ??
}
driver = new ChromeDriver();// Polymorphism or Upcasting ??
Polymorphism - Polymorphism means more than one form, same object performing different operations
Casting - Automatic type conversion
Could anyone please explain me the difference?