Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.spec;
- import com.spec.model.Student;
- /**
- *
- * @author Admin
- */
- public class Test3 {
- //
- public static void doSomething(Object o){
- System.out.println("o.toString=" + o.toString());
- //
- if(o instanceof Student){
- System.out.println("=" + ((Student)o).getInstituteCode());
- }
- }
- //
- public static void main(String[] args) {
- //
- Object o = null;
- Object o1 = "asfasfasf";
- int[] arr = {1, 2, 3};
- Object o2 = arr;
- Object o3 = 10;
- //
- Object o4 = new Student("Nick", 10);
- System.out.println("o4.toString()=" + o4.toString());
- //
- boolean res = o4.equals(o3); // true - объекты равны, false - объекты не равны
- System.out.println("res=" + res);
- //
- String s2 = "HELLO";
- String s3 = "HELLO";
- // сравнение строк
- if(s2.equals(s3)){
- System.out.println("s2 == s3");
- }else{
- System.out.println("s2 != s3");
- }
- //
- Object k = new Student("Nick", 10);
- if(k instanceof Student){
- System.out.println("k экземпляр Student!!!");
- }
- if(k instanceof Object){
- System.out.println("k экземпляр Object!!!");
- }
- doSomething(new Student("Nick", 10));
- doSomething("Nick");
- doSomething(new int[]{1,2});
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement