一些关于StringAPI的题目

一:知识点

1.字符串"你好北京"中每个字符占用2个内存字节数。字符串底层由字符数组构成,每个字符占用内存2个字节。

二:代码题

1.实现Point类的equals方法,具体逻辑为:成员变量x和y分别相等的Point对象被视为相等。

public class Point{

private int x;

private int y;

......

public boolean equals( Object obj){

   if ( ! (obj instanceof Point ) ) return false;

   if ( ! (Point)obj.x) == this.x && ( (Point)obj).y == this.y {

    return true;

}}}

使用instanceof 运算符判断一个对象是否属于Point类,若不判断,运行时会报错:ClassCastException.

猜你喜欢

转载自www.cnblogs.com/yuan-zhou/p/10193150.html
今日推荐