I have a base class and a derived class. The code I am writing is
class Base {
...
}
class derived extends base {
}
class Main {
public static void main(String[] args){
derived d = (derived) new Base(); //throws a ClassCastException
}
}
How is this handled? I would like to call the base class methods without the use of super keyword.
Baseis not aDerivedso it cannot be cast toDerivedDerivedis aBaseso it can be casted toBase;)