polymorphisim

Solutions on MaxInterview for polymorphisim by the best coders in the world

showing results for - "polymorphisim"
Niko
07 Jul 2020
1Polymorphism means objects behave in different forms. 
2■ It occurs when parent class/interface 
3calls to child class' objects 
4Sub class can never be the reference type of Super Class Object
5The reference of an object decides what is accessible.
6Abstract class and interface are meant to be reference type,
7CAN NEVER BE IN OBJECT TYPE
8Static polymorphism. Ex: method overloading.  
9Dynamic polymorphism Ex: method overriding 
10EXAMPLE: WebDriver driver = new ChromeDriver(); 
11driver.get()-> chrome, firefox
12we are initializing Chrome browser using 
13Selenium WebDriver. It also means we are creating 
14a reference variable (driver) of the interface (WebDriver) 
15and creating an Object (from ChromeDriver class). 
16I am using Polymorphism In my framework in Driver Class. 
17By making return type WebDriver I will be able to return 
18ChromeDriverObject and FireFoxDriverObject. That’s how I achieve 
19multi browser testing.
20Reference type decides what can be called or accessed
21WebDriver driver = getDriver();
22getDriver() ==> chrome, firefox, ...
23        
24List<WebElement> list = new ArrayList<>();
25List being reference to ArrayList. List is a super type of ArrayList. 
26Map being reference to HasMap. Set is being reference to HashSet.
similar questions
compile time polymorphism