20140423面试题总汇

1、byte b= 255 ; 报错么?

报错,byte的范围是 -128~127

另外int的范围是-2^31 ~ 2^31-1

2、int $x; 和int #x; 会报错么?

#x会报错,java命名规范:

$ 、字母、下划线开头都行,后面的可以是数字、字母、下划线.


3、以下程序不会不会报错?为什么?


public class B5Mtest {

	static int k ;
	public static void main(String[] args) {
		
		System.out.println(k);

	}

}



输出 0


4、子类能否缩小父类的访问权限?能不能放大?

不能缩小,能够放大。


public class B5MC1 {
	protected void printHello(){
		System.out.println("Hello class1");
	}
}



public class B5MC2 extends B5MC1{
	public void printHello(){
		System.out.println("Hello class1");
	}
}



类2改成private报错。


另外附上访问权限:


包外        子类         包内         类内 
public      yes        yes          yes         yes 
protected   no         yes          yes         yes 
default     no         no           yes         yes 
private     no         no           no          yes
5、static 方法能不能被重载?


能够被重载,也能够被覆盖。

6、以下输出是什么?


public class B5MC1 {
	
	void	 show(){
		System.out.println("static show C1");
	}	
}



public class B5MC2 extends B5MC1{

	static void	 show(){
		System.out.println("static show C2");
	}
	
	public static void main(String[] args) {
		B5MC2 b = new B5MC2();
		b.show();
	}
}



编译报错。子类不能用static 覆盖父类方法。


7、运行时异常和检查式异常有哪些?

运行时异常:(都继承了RuntimeException)

ClassCastException
ConcurrentModificationException
IndexOutOfBoundsException
NullPointerException


检查式异常:


IOException
SQLException

8、下面程序输出是什么?

public static void main(String[] args) {
		int num1 = 1;
		Integer num2 = 1;
		Integer num3 = new Integer(1);
		Integer num4 = Integer.valueOf(1);
		
		System.out.println(num1 == num2);
		System.out.println(num2 == num3);
		System.out.println(num3 == num4);
		System.out.println(num4 == num1);
		System.out.println(num4 == num2);
		
	}



输出;

true
false
false
true
true



10、下面程序的输出是什么?

public static void main(String[] args) {
		String s1 = "ab"+"cd";
		String s2 = "abcd";
		String s3=  new String("abcd");
		String s4= s3;
		String s5= s3;
		
		System.out.println(s1==s2);
		System.out.println(s2==s3);
		System.out.println(s4==s5);
	}



输出;

true
false
true




转载于:https://my.oschina.net/kanlianhui/blog/225584

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值