Advertisement
sergAccount

Untitled

Aug 23rd, 2020
1,357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 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.spec;
  7.  
  8. import com.spec.model.Student;
  9.  
  10. /**
  11.  *
  12.  * @author Admin
  13.  */
  14. public class Test3 {  
  15.     //
  16.     public static void doSomething(Object o){
  17.         System.out.println("o.toString=" + o.toString());
  18.         //
  19.         if(o instanceof Student){
  20.             System.out.println("=" + ((Student)o).getInstituteCode());
  21.         }
  22.     }    
  23.     //
  24.     public static void main(String[] args) {
  25.         //
  26.         Object o = null;
  27.         Object o1 = "asfasfasf";        
  28.         int[] arr = {1, 2, 3};        
  29.         Object o2 = arr;        
  30.         Object o3 = 10;
  31.         //
  32.         Object o4 = new Student("Nick", 10);        
  33.         System.out.println("o4.toString()=" + o4.toString());  
  34.         //
  35.         boolean res = o4.equals(o3); // true - объекты равны, false - объекты не равны
  36.         System.out.println("res=" + res);    
  37.         //
  38.         String s2 = "HELLO";
  39.         String s3 = "HELLO";
  40.         // сравнение строк
  41.         if(s2.equals(s3)){
  42.             System.out.println("s2 == s3");
  43.         }else{
  44.             System.out.println("s2 != s3");
  45.         }
  46.         //
  47.         Object k = new Student("Nick", 10);      
  48.         if(k instanceof Student){
  49.             System.out.println("k экземпляр Student!!!");
  50.         }
  51.         if(k instanceof Object){
  52.             System.out.println("k экземпляр Object!!!");
  53.         }
  54.        
  55.         doSomething(new Student("Nick", 10));
  56.         doSomething("Nick");
  57.         doSomething(new int[]{1,2});  
  58.     }
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement