1. Object类概述

  • 是类层次结构的根类
  • 每个类都使用 Object 作为超类
  • 所有类都直接或者间接的继承自该类
  • 所有对象(包括数组)都实现这个类的方法。

 

2. Object的构造方法

  • public Object()
  • 回想面向对象中为什么说:
  • 子类的构造方法默认访问的是父类的无参构造方法

 

3. Object类的hashCode()方法

  • Object类的hashCode()方法
    • 案例演示

      • package com.heima.object;
        
        import com.heima.animal.Cat;
        
        
        public class Demo1_HashCode {
        
            /**
             * @param args
             */
            public static void main(String[] args) {
                Object obj1 = new Object();
                int num = obj1.hashCode();
                System.out.println(num); //输出7309408
                
                Cat c1 = new Cat();
                System.out.println(c1.hashCode()); //输出26905665
                
                Cat c2 = new Cat();
                System.out.println(c2.hashCode()); //输出23994111
                
                
            }
        
        }
        hashCode()方法

相关文章:

  • 2021-09-09
  • 2022-12-23
  • 2022-02-10
  • 2021-08-25
  • 2022-03-04
  • 2018-08-09
  • 2022-01-13
  • 2022-01-20
猜你喜欢
  • 2022-12-23
  • 2021-10-19
  • 2021-08-21
  • 2022-12-23
  • 2021-10-28
  • 2022-01-19
相关资源
相似解决方案