Answers for "What’s class cast exception?"

0

What’s class cast exception?

lass cast excep: you are attempting to cast one class to another. 
what is the precondition to cast a class? IS A relation. 
So when we have a class extending another class. 
as long as there is IS A relation between classes you can cast. 
if reference type is parent, we can downcast it to the child reference type 
RemoteWebDriver is parent of ChromeDriver and FireFoxDriver:  // Polymorphism
RemoteWebDriver driver1 = new ChromeDriver(); // upcasting implicitly done
 FirefoxDriver driver2 = (FireFoxDriver) driver1; // downcasting 
Class cast exceptions means there is no IS A relation // downcasting
you need to have the actual object in order to have the instance.
Posted by: Guest on May-28-2021

Code answers related to "What’s class cast exception?"

Browse Popular Code Answers by Language