为了验证一些问题

package wang;

public class Test1 {
	public static void main(String[] args) {
		// int x = 3,y=4;
		// Integer x = 2;
		// Integer y = 2;
		// Integer m = new Integer(2);
		// Integer n = new Integer(2);
		// System.out.println(x == y);
		// System.out.println(m == n);
		// System.out.println(m.equals(n));
		// System.out.println(Math.ceil(-11.7));
		// System.out.println(20000>>3);
		// // System.out.println(24>>3);
		// String s = new String("abc");
		// String s1 = "abc";
		// String s2 = new String("abc");
		// System.out.println(s == s1);
		// System.out.println(s == s2);
		// System.out.println(s1 == s2);
		// System.out.println(".....");
		// System.out.println(s.equals(s1));
		// System.out.println(s.equals(s2));
		// System.out.println(s2.equals(s1));
		// A a = new B();
		// System.out.println("---c1---");
		// C c1 = null;
		// c1.show();
		System.out.println("---c2---");
		C c2 = new C(5);
		c2.show();
		System.out.println("---c3---");
		C c3 = new C();
		c3.show();
		System.out.println("---c4---");
		C c4 = new C(1983);
		c4.show();
		System.out.println("*********************************");
		for(int i =0;i < 10; i++){
			for(int j = i; j < 10; j++){
				if(j == 3){
					System.out.println("i = " + i + "\t\tj = " + j);
					System.out.println("在内循环中即将执行break语句.");
					break;
				}
				System.out.println("此时此刻,i = " + i + "\tj = " + j);
			}
		}
	}
}

class C {
	public void show() {
		System.out.println("in show(),x = " + x);
	}

	int x;
	static {
		System.out.println("静态代码块.x = ");
	}

	{
		System.out.println("构造代码块.x = " + x);
	}

	C() {
		System.out.println("默认无参构造函数.x = " + x);
	}

	C(int x) {
		this.x = x;
		System.out.println("带参数的构造方法.x = " + x);
	}
}

abstract class A {
	int x;

	public void show() {
	}

	abstract void show2();
}

class B extends A {

	@Override
	void show2() {
	}

}

根据输出结果可以看出:

1,static代码块只执行一次.

2,构造代码块在每次创建对象的时候执行,顺序上优先于构造函数.

3,break只跳出当前的循环.

4,==号永远在比较内存地址.

5,equals默认调用Object的比较地址的功能.自定义对象需要一般需要重写这个函数.

6,>>操作符只能操作整数,并且运算结果的最小值0.


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值