The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).
这是文档里面equals方法的说明,也就是说如果引用同一个对象的时候为true,否则为false。
下面这个是getClass的文档里面说明。
Returns the runtime class of this Object. The returned Class object is the object that is locked by static synchronized methods of the represented class.- class Demo
- {
- void Show(){System.out.println(1);}
- }
- class Ins extends Demo
- {
- void Method(){System.out.println(2);}
- }
- class Demo2
- {
- public static void main(String []args)
- {
- Ins ins = new Ins();
- Demo demo = new Demo();
- Object obj = new Object();
- Demo demo2 = new Demo();
- Demo demo3 = demo2;
- System.out.println(demo instanceof Ins);
- System.out.println(demo.equals(ins));
- System.out.println(demo instanceof Object);
- System.out.println(demo.equals(obj));
- System.out.println(demo.getClass()==obj.getClass());
- System.out.println(demo2.getClass()==demo.getClass());
- //System.out.println(demo2.==demo3);
-
- }
- }
复制代码 |
|