BasePage.java
public class BasePage {
//do stuff
}
Center.java
public class Center {
public BasePage click(){
click(button);
return new BasePage(this);
}
// do other stuff
}
public class Helper {
protected Center center;
// do stuff
}
Page.java
public class Page extends BasePage {
//do stuff
}
TestClass.java
public class TestClass extends Helper {
private Page page;
// I can use "center.click()" because TestClass extends from Helper,
// and "center" is a protected variable in Helper
// "center.click()" returns type 'BasePage'
// 'page' is a type 'Page' which extends 'BasePage'
// So why can't I put the result of "center.click()" into 'page' ?
page = center.click();
}
Take this example:
The easiest way to understand it is, the container should be bigger than the type of object it is storing. In this case, Superclass is bigger than Subclass, that’s why the second statement is correct.
If you need to use the first statement by any means, try casting.