关于object类
来源:互联网 发布:java多态的实现方式 编辑:程序博客网 时间:2024/06/04 17:56
class Point
{
public int x, y;
public Point(int x, int y)
{
this.x =
this.y = y;
}
public override bool Equals(object obj)
{
// If this and obj do not refer to the same type, then they are not equal.
if (obj.GetType() != this.GetType()) return false;
// Return true if x and y fields match.
Point other = (Point)obj;
return (this.x == other.x) && (this.y == other.y);
}
// Return the XOR of the x and y fields.
public override int GetHashCode()
{
return x ^ y;
}
// Return the point's value as a string.
public override String ToString()
{
return String.Format("({0}, {1})", x, y);
}
// Return a copy of this point object by making a simple field copy.
public Point Copy()
{
return (Point)this.MemberwiseClone();
}
}
public sealed class App
{
static void Main()
{
// Construct a Point object.
Point p1 = new Point(1, 2);
// Make another Point object that is a copy of the first.
Point p2 = p1.Copy();
// Make another variable that references the first Point object.
Point p3 = p1;
// The line below displays false because p1 and p2 refer to two different objects.
Console.WriteLine(Object.ReferenceEquals(p1, p2));
// The line below displays true because p1 and p2 refer to two different objects that have the same value.
Console.WriteLine(Object.Equals(p1, p2));
// The line below displays true because p1 and p3 refer to one object.
Console.WriteLine(Object.ReferenceEquals(p1, p3));
// The line below displays: p1's value is: (1, 2)
Console.WriteLine("p1's value is: {0}", p1.ToString());
Console.ReadLine();
}
}
// This code produces the following output.
//
// False
// True
// True
// p1's value is: (1, 2)
- 关于Object类
- 关于object类
- 关于接口与Object 类的关系
- 关于Object类的equals()和hashcode()
- 关于接口与Object 类的关系
- 关于object类的初次认识
- 关于Object类的几个方法
- 关于java Object类的公有方法
- 关于javascript,[object,object]是什么?
- 关于OBJECT-C
- 关于Object.style.backgroundPosition
- 关于Object与String
- 关于Object-C
- 关于OBJECT标签
- 关于Object-Oritented Javascript
- 关于object-c
- 关于 Object...args
- 关于Object=null
- 安装完Fedora 16 您需要做什么?
- Fedora16安装后的工作
- Poj 2492 A Bug's Life
- 540 - Team Queue***
- ext中联动combo远程加载选中的解决
- 关于object类
- Android日记之2012/01/20(公告)
- Poj 2524 Ubiquitous Religions
- Python 去除列表中重复的元素
- 2012-Linux->17 Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,2)
- 分享读取各大主流邮箱通讯录(联系人)、 MSN好友列表的的功能【升级版(2.0)】 .net版
- USACO Section 4.4 Frame Up - DFS即可~
- oracle简单查询
- 应聘之前应该看看