Java Tutorial 70 - instanceof Operator

Publié le: 24 avril 2020
sur la chaîne: Ken
156
3

In this tutorial, I will show you how to use the instanceof operator. It tests whether an object is an instance of a class.

For example, if an object is not an instance of Student (either Student or Undergraduate or Graduate), it cannot be cast into a variable of Student. Using non-student object, getCode() would cause a compile error, because the Employee (or Faculty or Staff) class does not have the getCode method. The compiler cannot find a match for list.get(i).getCode. Therefore, it is necessary to cast list.get(i) into the Student type to tell the compiler that list.get(i) is also an instance of Student.


Sur cette page du site, vous pouvez voir la vidéo en ligne Java Tutorial 70 - instanceof Operator durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Ken 24 avril 2020, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 156 fois et il a aimé 3 téléspectateurs. Bon visionnage!