Hello java_fun2007
If you create an instance of DVD or of Cassete, it is also an instance of Video, since DVD and Cassete are extended from Video and contains all the inheritable attributes and methods of Video. That means that you can have a variable, media, that can contain a DVD or Cassete. So lets a media variable with a DVD in it. The
new keyword use used to create instances of a class.
Now, we know that media is an Video but we might want to know if it is a DVD or a Cassete. For that we use the
instanceof keyword for a boolean test.
if (media instanceof DVD)
System.out.println("I'm a DVD");
if (media instanceof Cassete)
System.out.println("I'm a Cassete");
I use this stuff regularly, so I hope this helped you.
