In addition to Henry's comment who explained that you could do the following:
Object obj = new BankAccount();
BankAccount s = (BankAccount) obj;
System.out.println(s instanceof BankAccount);
You should always keep in mind that variables are some kind of remote control.
The first line uses a Object
remote control to control a BankAccount
. This is possible because everything is an Object
... this means you can use this remote control to control all objects. But you will also see that this control only supports operations that are defined in the Object
class which means all Objects
have.
The second line at the right side of the equation states that the referenced Object
is actually a BankAccount
. On the left side of the equation you force to create a new remote control that is able to control BankAccount
objects.