Ejemplo 1: conversión ascendente de Java
Upcasting is casting a subtype to a supertype,
going up in the inheritance tree.
It is done implicitly
in order to use method available on any
interface/class, the object should be of
same class or of class implementing the interface.
WebDriver driver = new ChromeDriver();
or
TakeScreenShot ts = new ChromeDriver();
Ejemplo 2: downcasting en java
Downcasting is casting to a subtype,
going down in the inheritance tree.
It is done to access sub class features.
It has to be done manually
(TakeScreenShot)driver).takeScreenShot();
Ejemplo 3: upcasting vs downcasting en java
Upcasting is casting a subtype to a supertype,
going up in the inheritance tree.
It is done implicitly
in order to use method available on any
interface/class, the object should be of
same class or of class implementing the interface.
WebDriver driver = new ChromeDriver();
or
TakeScreenShot ts = new ChromeDriver();
Downcasting is casting to a subtype,
going down in the inheritance tree.
It is done to access sub class features.
It has to be done manually
(TakeScreenShot)driver).takeScreenShot();
Ejemplo 4: lo que es abatido
Downcasting is casting to a subtype,
going down in the inheritance tree.
It is done to access sub class features.
It has to be done manually
(TakeScreenShot)driver).takeScreenShot();
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)