1Upcasting is a type of object typecasting in which a child object is typecasted to a parent class object. By using the Upcasting, we can easily access the variables and methods of the parent class to the child class. Here, we don't access all the variables and the method. We access only some specified variables and methods of the child class. Upcasting is also known as Generalization and Widening.
2
3
1A process of converting one data type to another is known as Typecasting and Upcasting and Downcasting is the type of object typecasting. In Java, the object can also be typecasted like the datatypes. Parent and Child objects are two types of objects. So, there are two types of typecasting possible for an object, i.e., Parent to Child and Child to Parent or can say Upcasting and Downcasting.
2
1Upcasting is casting a subtype to a supertype,
2going up in the inheritance tree.
3It is done implicitly
4 in order to use method available on any
5 interface/class, the object should be of
6 same class or of class implementing the interface.
7 WebDriver driver = new ChromeDriver();
8or
9 TakeScreenShot ts = new ChromeDriver();
1Upcasting is casting a subtype to a supertype,
2going up in the inheritance tree.
3It is done implicitly
4 in order to use method available on any
5 interface/class, the object should be of
6 same class or of class implementing the interface.
7 WebDriver driver = new ChromeDriver();
8or
9 TakeScreenShot ts = new ChromeDriver();
10
11Downcasting is casting to a subtype,
12going down in the inheritance tree.
13It is done to access sub class features.
14It has to be done manually
15
16(TakeScreenShot)driver).takeScreenShot();
17
18