Java面试题 -- 个人整理

参数与引用相关:

(1) 这道题相当有价值!必须对堆栈的概念熟悉!

static void test(String str, List<String> lst){
		
		str.replace("1", "2");
		lst.add("b");
		lst = new ArrayList<String>();
		lst.add("c");
		
	}
	
	public static void main(String[] args) {
		
		String str = "1";
		List<String> lst = new ArrayList<String>();
		lst.add("a");
		test(str, lst);
		
		for(String s : lst) System.out.print(s);
		System.out.println(str);
	}

类加载相关:

(1)

public class InitTest {

	/**
	 * @param args
	 */
	
	{
		System.out.println("a");
	}
	
	static{
		System.out.println("b");
	}
	
	public InitTest(){
		System.out.println("c");
	}
	
	public static void main(String[] args) {
		System.out.println("d");
		new InitTest();
		new InitTest();
		System.out.println("e");

	}

}



Exception相关:

(1)

static int test(){
		try{
			System.out.println("1");
			throw new RuntimeException();
		} catch(RuntimeException e){
			System.out.println("3");
			return 4;
		}catch(Exception e){
			System.out.println("5");
			return 6;
		}finally{
			System.out.println("7");
			return 8;
		}
	}
	
	public static void main(String[] args) {
		
		System.out.println(test()); // 这里输出的内容?
	}


(2)在方法内抛出RuntimeException, 是否需要在方法中声明?

public void doSomething(){
		throw new RuntimeException();  // 是否合法?
	}


流程题相关:

(1)

int a = 1;
		int b = 10;
		do{
			
			b -= a;
			a++;
			
		}while(b-- < 0);
		
		System.out.println(b);


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值