Java笔记--面试题

来源:互联网 发布:手机h5页面制作软件 编辑:程序博客网 时间:2024/04/30 15:31

这是我自己面试的时候做的一些面试题,希望对你有用。

1String str1 = "java";String str2="java";System.out.println(str1 == str2);String str3 = new String("java");System.out.println(str1 == str3);String str4 = new String("java");System.out.println(str3 == str4);System.out.println(str3.equals(str1));答案: true false false true
2Integer num1 = new Integer(123);Integer num2 = new Integer(123);System.out.println(num1 == num2);Integer num3 = Integer.valueOf(123);Integer num4 = Integer.valueOf(123);System.out.println(num1 == num3);System.out.println(num4 == num3);答案:true false true
3)class Base{    public int a = 10;    public void test(){        System.out.println("父类被子类重写的方法");    }    public void test1(){        System.out.println("父类的方法");    }}class Car extends Base{    public int a = 20;    public void test(){        System.out.println("子类重写父类的方法");    }    public void test2(){        System.out.println("子类的方法");    }}public static void main(String [] args){Base b = new Car();System.out.println(b.a);b.test();b.test1();b.test2();}答案:10     子类重写父类的方法     父类的方法     报错!!!

(4)编程杨辉三角

public static void main(String[] args) {      int triangle[][]=new int[10][];// 创建二维数组      // 遍历二维数组的第一层      for (int i = 0; i < triangle.length; i++) {          triangle[i]=new int[i+1];// 初始化第二层数组的大小          // 遍历第二层数组          for(int j=0;j<=i;j++){              // 将两侧的数组元素赋值为1              if(i==0||j==0||j==i){                  triangle[i][j]=1;              }else{// 其他数值通过公式计算                  triangle[i][j]=triangle[i-1][j]+triangle[i-1][j-1];              }              System.out.print(triangle[i][j]+"\t");         // 输出数组元素          }          System.out.println();               //换行      }}

(5)编程九九乘法表

public static void main(String[] args) {     //外层循环控制行数,9行。      //内存循环控制列数、数量。      for(int i=1;i<=9;i++)       {          for(int j=1;j<=i;j++)          {              System.out.print(i+"*"+j +"=" +(i*j) +"\t");          }          //换行显示          System.out.println();      }  }

(6)spring的好处
(7)hibernate的对象状态和状态之间的转换
(8)接口和抽象类的区别

0 0