• java几道简单的面试题目


    1.   请问以下程序会输出什么?

      public   class   Test   { 
        public   static   void   main(String[]   args)   { 
          Parent   parent   =   new   Parent(); 
          Parent   child   =   new   Child(); 
          System.out.println(parent.getName()); 
          System.out.println(child.getName()); 
        } 
      }
      class   Parent   { 
        public   static   String   getName()   { 
          return   "Parent "; 
        } 
      }
      class   Child   extends   Parent   { 
        public   static   String   getName()   { 
          return   "Child "; 
        } 
      }
    2.   请问以下程序会输出什么?
      public   class   Test   { 
        public   static   void   main(String[]   args)   { 
          for(int   i   =   0;   i   <=   10;   i++) 
            Integer   k   =   new   Integer(i); 
          System.out.println( "Java   Puzzlers "); 
        } 
      }
    3.   请补全   i   的声明(要求:i   不允许为   float、double、Float   和   Double   类型)让其能输出“Hello   World”。
      public   class   Test   { 
        public   static   void   main(String[]   args)   { 
          ________________;   //   补全   i   的声明 
          if(   i   !=   i   +   0)   { 
            System.out.println( "Hello   World "); 
          } 
        } 
      }
    4.   请问以下程序的输出结果是什么?
      import   java.math.BigInteger;
      public   class   Test   { 
        public   static   void   main(String[]   args)   { 
          BigInteger   one   =   new   BigInteger( "1 "); 
          BigInteger   two   =   new   BigInteger( "2 "); 
          BigInteger   three   =   new   BigInteger( "3 "); 
          BigInteger   sum   =   new   BigInteger( "0 "); 
          sum.add(one); 
          sum.add(two); 
          sum.add(three); 
          System.out.println(sum.toString()); 
        } 
      }
    5.   请将下面程序中的空格补全(要求见程序中)
      //   忽略   import   语句 
      public   class   Test   { 
         
        public   static   void   main(String[]   args)   {     
          List <String>   list   =   new   ArrayList <String> (); 
          list.add( "d "); 
          list.add( "c "); 
          list.add( "c "); 
          list.add( "a "); 
          list.add( "a "); 
          list.add( "b "); 
          list.add( "b ");     
          list   =   removeDuplicate(list); 
          //   输出的结果应是“d   c   a   b   ” 
          for(String   str   :   list)   { 
            System.out.print(str   +   "   "); 
          } 
        } 
         
        /** 
           *   方法功能:移除   List   中重复的元素,并保持原有的顺序 
           */ 
        public   static   <T>   List <T>   removeDuplicate(List <T>   list)   { 
          //   把空格处完善 
          return   ____________________________________; 
        } 
      }
    以上的题目,你能答对多少呢?
  • 相关阅读:
    51nod 1380 夹克老爷的逢三抽一 堆 脑洞题
    洛谷P2168 荷马史诗 堆 哈夫曼树
    HDU 4343 Interval query 倍增思想, DP
    洛谷P1969 积木大赛 贪心 差分
    codves1052 地鼠游戏 贪心
    hdu6031 Innumerable Ancestors
    Codeforces 278C Learning Languages(并查集) 求连通块
    [LeetCode]80. Remove Duplicates from Sorted Array II删除数组中的重复值
    [LeetCode]86. Partition List分离链表
    [LeetCode]42. Trapping Rain Water雨水填坑
  • 原文地址:https://www.cnblogs.com/amwuau/p/6214546.html
Copyright © 2020-2023  润新知