A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

D:\黑马it\自己学习笔记\Day11

5 个回复

倒序浏览
[mw_shl_code=applescript,true]package com.heima;

public class Demo_Object {

        /**
         * @param args
         */
        public static void main(String[] args) {
                Student s = new Student("xxx",28,"yyy");
                Student s2 = new Student("xxx",28,"yyy");
//                getClass()是用来获取一个对象的字节码文件和getName()是用来获取这个字节码文件的全类名,的使用
//                这两个方法一个是Object类下的方法,一个是Class类下的方法,
                Class clazz = s.getClass();
                String classname = clazz.getName();
                System.out.println(classname);
               
//                hashCode();方法的使用,主要是算出对象的哈希值
                int y = s.hashCode();//可以直接调用
                int m = s2.hashCode();
                System.out.println(m+"......."+y);
//                ---------------------------------------------------
                boolean x = s.equals(s2);
                System.out.println(x);
//                这里直接调用toString();方法直接打印对象名,则会输出对象的哈希值;BUT
//                直接打印哈希值对我们来说没有什么意义,所以我们要重写toString()方法;
//                因为这个方法是object里面的方法,而他又是父类,所以我们在子类中重写它
//                谁的对象调用它,就把方法重写在谁下面
                String m1 = s.toString();
                System.out.println(m1);
        }
       
}
[/mw_shl_code]
回复 使用道具 举报
看不懂,学习一下!!
回复 使用道具 举报
敲敲乐z 发表于 2016-8-10 00:36
看不懂,学习一下!!

你的技术分怎么来的,我好缺这个呀{:2_31:}
回复 使用道具 举报
冬冬宋 发表于 2016-8-10 01:10
你的技术分怎么来的,我好缺这个呀

慢慢攒分,发帖,回帖就有了!
回复 使用道具 举报
阿西吧好吧
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马