20070929迅雷面试部分题

http://blog.csdn.net/fenglibing/article/details/1808487

20070929迅雷面试部分题
在做的时候,把部份觉得有意义的题记录下来,所谓有意义,就是我不太会的,不太懂的,不太明白的,平时没有注意的等等,结果一做,发现居然只有几个没有错。
1、结出如下程序的打印结果
父类:
publicclass Father {
    public Father()
    {
       System. out .println( "Father!" );
    }
    publicvoid testA()
    {
       System. out .println( "Father A" );
    }
    publicvoid testB()
    {
       System. out .println( "Father B" );
    }  
}
子类:
publicclass Children extends Father{
    public Children()
    {
       System. out .println( "Childern" );
    }
    publicvoid testA()
    {
       System. out .println( "Childern A" );
    }
    publicvoid testB()
    {
       System. out .println( "Childern B" );
    }  
    publicstaticvoid main(String[] arg)
    {
       Father father= new Children();
       father.testA();
       father.testB();
    }
}
问打印结果:
解:主要考的是向上转型,这是调用的还是子类的方法,结果如下:
Father!
Childern
Childern A
Childern B
但如果我把测试类改成这样:
Children father= new Children();
打印结果同上。
2、字符串的比较,打印下面的结果:
publicclass StringCompare {   
    publicstaticvoid main(String[] arg)
    {
       String a= "www" ;
       String b=a;
       String c= new String( "www" );String d=new String(a);//这个去比较试试
       System. out .print((a==b)+ " " );
       System. out .print((a==c)+ " " );
       System. out .print((b==c)+ " " );
       System. out .print((a.equals(c)));
    }
}
解: a,b 是同一个对象,所以相等;只有对象相同是,等于的结果才为真。 Equals 比较的是值,值相等的等于结果为真。
打印如下:
true false false true
3 、运行该程序会出现什么样的结果,
public class SychorinizedTest {
    public SychorinizedTest()
    {
       System.out.println("SychorinizedTest");
    }
    /**
     * @param args
     */
    public static void main(String[] args) {
       // TODO Auto-generated method stub
       SychorinizedTest test=new SychorinizedTest();
       test.sTest();
    }
    void sTest()
    {
       SychorinizedTest a=this;
       SychorinizedTest b=this;
       synchronized(a)
       {
           try {
              b.wait();
              System.out.println("B is waked up");
           } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
           }
       }
    }
}
1 )、编译错误
2 )、运行错误
3 )、运行异常
4 )、打印结果: SychorinizedTest
5 )、打印结果: SychorinizedTest
              B is waked up
答案:
SychorinizedTest
4 、下面运行的结果是怎么样的:
父类:
publicclass Father {
    public Father()
    {
       System. out .println( "Father!" );
    }
    publicvoid testA()
    {
       System. out .println( "Father A" );
    }
    publicvoid testB()
    {
       System. out .println( "Father B" );
    }  
}
子类:
public class Children extends Father{
    public Children()
    {
       System.out.println("Childern");
    }
    public void testA()
    {
       System.out.println("Childern A");
    }
    public void testA(String a)
    {
       System.out.println(a);
    }
    public String testA()
    {
       System.out.println("Childern A");
    }
    public String testA(String a)
    {
       System.out.println("Childern A");
    }
    public void testB()
    {
       System.out.println("Childern B");
    }
   
    public static void main(String[] arg)
    {     
       Children c=new Children();
    }
}
1 )、编译错误
2 )、运行错误
3 )、正常运行
5 、写出下面程序运行的结果:
publicclass StringBufferTest {
   
    publicstaticvoid main(String[] arg)
    {     
       StringBufferTest t= new StringBufferTest();
       t.test();
    }
    void test()
    {
       int x=4;
       StringBuffer sb= new StringBuffer( "..sdfgfe" );
       sb.delete(3,6);
       System. out .println(sb);
       sb.insert(1, "aa" );
       if (sb.length()>6)
       {
           x=sb.length();
       }
       sb.delete(x-3, x-2);
       System. out .println(sb);
    }
}
答案: .aa.fe
6 String,StringBuilder,StringBuffer 的区别及性能比较、共同特性
 〔网上找〕
7 、给出下面程序的执行顺序:
publicclass Father {
    //1
    String a = "aaaaaa" ;
    public Father()
    {
       //2
       System. out .println( "Father" );
    }  
}
class Child extends Father
{
    //3
    String b = "bbbbbbb" ;
    public Child()
    {
       //4
       System. out .println( "Children" );
    }
    //5
    static {
       String tt= "ttttttt" ;
    }
}
答案:
我用 DEBUG 得到的如下显示:
Source breakpoint occurred at line 23 of Father.java.
Source breakpoint occurred at line 5 of Father.java.
Source breakpoint occurred at line 9 of Father.java.
Father
Source breakpoint occurred at line 15 of Father.java.
Source breakpoint occurred at line 19 of Father.java.
Children
也即顺序是:
先执行静态初使化,然后去子类的构造函数,发现有继承,然后转向父类,发现父类有变量初使化,于是执行父类变量的初使化,然后执行父类的构造函数,再回到子类的构造函数,发现有全局变量要初使化,初使化子类的全局变量,再执行子类的构造函数
顺序为: 5 1 2 3 4
8 、现在一个表,有姓名、性别、年龄,字段分别为 varchar(20),varchar(20),int ,现有表中已经有上百万条记录了,在姓名上建索引,现在有一个文本文件,已经格式化为姓名、性别、年龄,写一个函数,怎么样一次性的将该文件中的数据以最快的速度导入到数据库中。
如有函数
save(Connection c,File f)
{
    // 操作
}
实现该函数
解:
〔暂无解〕

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值