For = with object references, if the type of the left operand is a class C, then the type of the right operand must be a subclass of C or the null value. : Reference Type Casting « Type Casting « SCJP
publicclass MainClass{
publicstaticvoid main(String[] argv){
MyClass myClass = new MyClass();
MySubclass mysubclass = new MySubclass();
myClass = mySubclass();
System.out.println();
}
}
class MyClass{
}
class MySubclass extends MyClass{
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method mySubclass() is undefined for the type MainClass
at MainClass.main(MainClass.java:5)
For = with object references, if the type of the left operand is a class C, then the type of the right operand must be a subclass of C or the null value.