zoukankan      html  css  js  c++  java
  • Java Object类

    Object类中的Method有很多,先记几个上课学到的:

    public boolean equals(Object o);
    //返回调用对象(this)与o对象是否相同
    //return o == this
    //通常情况是要进行覆盖,判断两个对象是否是同一类型以及封装的值是否相同
    public class Student{
        private String sname;
        private int age;
        private String sno;
    
        public boolean equals(Object o){
            if(null == o) return false;
            if(o.getClass() == this.getClass())
            {
                Student s = (Student)o;
                return this.sname.equals(s.sname) &&
                        this.age == s.age &&
                        this.sno.equals(s.sno)
            }
        }
    }

    Protected Object clone() throws CloneNotSupportedException

    Protected Object clone() throws CloneNotSupportedException
    //return a clone of this instrance
    //throws CloneNotSupportedException,如果这个类不写implements Cloneable,会抛出这个异常
    //这个复制是浅复制,只复制对象的属性值,而对于引用属性,则仅仅是复制引用
    //示例
    public class Student implements Cloneable{
       public String name;
       public int age;
    
        public static void main(String[] args) {
            Student s = new Student();
            s.name = "zhangsan";
            s.age = 18;
    
            try {
               Student s2 = (Student) s.clone();
                System.out.println(s.name);
                System.out.println(s2.name);
            }catch (CloneNotSupportedException r){
            }
        }
    }

    public String toString()

    public String toString()
    //returns :a string representation of the object.
    //默认为 getClass().getName() + '@' + Integer.toHexString(hashCode())

    protected void finalize() throws Throwable

    protected void finalize()
                     throws Throwable
                     //在虚拟机清理垃圾对象之前调用

    分割线---------------------------------------------------------------------------------------------------------------

    你若笃定,世界便不浮躁。
  • 相关阅读:
    如何在SAP中找表
    SQL SARG
    计算两个时间相差多少年月日的sql算法
    给WordPress添加微博功能
    sqlServer,oracle中case关键字的用法
    SSIS错误之"The Excel Connection Manager is not supported in the 64bit version of SSIS"
    Oracle编程艺术之设置环境
    Quest.Central.For.Databases.v6.1下载地址
    Oracle Database 11g SQL开发指南store模式脚本
    SQL中连接的种类和区别
  • 原文地址:https://www.cnblogs.com/zhangyue123/p/9277378.html
Copyright © 2011-2022 走看看