现在的位置: 首页 > 综合 > 正文

Java面试题

2013年08月01日 ⁄ 综合 ⁄ 共 1904字 ⁄ 字号 评论关闭

1

    public static void main(String[] args)
    {
        String s;
               

        System.out.println(s);
        }

init:
deps-jar:
Compiling 1 source file to D:/test/Test/build/classes
D:/test/Test/src/test/test.java:57: 可能尚未初始化变量 s
        System.out.println(s);
1 错误

2

    public static void main(String[] args)
    {
        int[] a = new int[5];

        System.out.println(a[1]);
        }

init:
deps-jar:
Compiling 1 source file to D:/test/Test/build/classes
compile-single:
run-single:
0
生成成功(总时间:0 秒)

3

/*
 * test.java
 *
 * Created on 2008年2月27日, 下午9:47
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package test;

/**
 *
 * @author rulinma
 */
public class test {
     
     static int i = 0;
     
    /** Creates a new instance of test */
    public test() {
    }
 
    public static int foo(int i)
    {
               try
            {
                if(i==1)
                {
                    i = i / 0 ;
                }
                else
                {
                    i=i+1;
                }
            }
            catch(Exception ex)
            {
                i = i+2;
                ex.getMessage();
                return i;
            }
            finally
            {
                i = i + 4;
                System.out.println(i);
            }
        i= i+5;
        return i;
    }
   
    public static void main(String[] args)
    {
       
        foo(0);
        foo(1);

        System.out.println(i);
        }

}

init:
deps-jar:
Compiling 1 source file to D:/test/Test/build/classes
compile-single:
run-single:
5
7
0
生成成功(总时间:0 秒)

4

    public static void main(String[] args)
    {
            String a[] = new String[1];
            try
            {
                System.out.println(a[3]);
            }
            catch(ArrayIndexOutOfBoundsException ex)
            {
                System.out.println(ex.toString());
            }
            catch(Exception e)
            {
                System.out.println(e.toString());
            }
     }

init:
deps-jar:
compile-single:
run-single:
java.lang.ArrayIndexOutOfBoundsException: 3
生成成功(总时间:0 秒)

 

抱歉!评论已关闭.