Advertisement
sergAccount

Untitled

Jul 10th, 2021
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.mycompany.ex19;
  7.  
  8. /**
  9.  *
  10.  * @author student
  11.  */
  12. public class Main2 {
  13.     //
  14.     public static void main(String[] args) {
  15.         // instanceof (результат работы - значение типа boolean)
  16.         String s = "HELLO JAVA";
  17.         boolean isString = s instanceof String;
  18.         System.out.println("isString=" + isString);
  19.         //  
  20.         Person p = new Employee("Ivan", "Ivanov", "Google");
  21.         //
  22.         boolean isPerson = p instanceof Person;
  23.         System.out.println("isPerson=" + isPerson);
  24.        
  25.         Employee e = new Employee("Ivan", "Ivanov", "Google");
  26.         boolean isEmployee = e instanceof Employee;
  27.         boolean isPerson1  = e instanceof Person;
  28.         System.out.println("e.isEmployee=" + isEmployee);
  29.         System.out.println("e.isPerson1="  + isPerson1);
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement