*设为首页
*加入收藏
热门关键字: JAVA
>>当前位置:Java大本营>认证考试>文章内容
今天的Java笔试题
作者: 发布时间:2008-02-04 00:34:20

今天面试做了一套Java笔试题,下面是我根据记忆,对题目进行的测试,我是把几个题目综合在一起进行测试的:
         TestB.java代码:

import java.util.*;
class Parant
{
       Parant()
      {
    System.out.println("parant");
}
static
{
    System.out.println("parant static");
}
{
     System.out.println("parant not static");
}
public void test(ArrayList list)
{
    System.out.println("parant list");
}
}
class Child extends Parant
{
Child()
{
    System.out.println("child");
}
static
    {
     System.out.println("child static");
}

       {
      System.out.println("child not static");
}
public void test(List list)
    {
     System.out.println("child list");
}
}
class TestB
{
      public static void main(String[] args)
      {
    //先调用父类的构造方法,然后调用子类的构造方法,不管static还是没有static的代码段,都会被执行
    Child ac=new Child();
    ArrayList al=new ArrayList();
    ac.test(al);              //输出的是parant list,子类没有重写父类的方法
    String a="aaa";
    String b="aaa";
    String c=new String("aaa");
    //如果要比较两个基本类型的值是否相等,请用= =;

         //如果要比较两个对象的地址是否相等,请用= =;

         //如果要比较两个对象(引用)是否一致,请用equals
    System.out.println(a==b);
    System.out.println(a.equals(c));
    int temp=99;
    test(temp);            //输出的是99
    System.out.println(temp);     //99
    System.out.println(test(temp));      //199
      }
      public static int test(int bb)
      {
    bb=bb+100;
    return bb;
}
}
interface A
{
void test2();     //接口类不能带有方法主体,接口中可以没有方法,编辑能通过
}
abstract class B
{
abstract void test3(); //如果没有abstract,必须有方法主体
void test4()
{
}
}

TestC.java:

class TestC
{
      public static void main(String[] args)
      {
    int a=test();
    System.out.println(a);          //输出的结果是3
}
public static int test()
{
    try
    {
     String s=null;
     s.substring(0,1);
     return 1;
    }
    catch(Exception e)
    {
     return 2;
    }
          finally         //如果没有finally,则输出2
      {
       return 3;
    }
}
}

TestD.java

import java.util.*;
class TestD
{
public static void main(String[] args)
{
     ArrayList a=new ArrayList();
     test1(a);
     System.out.println(a.size());      //输出是0
     test2(a);
     System.out.println(a.size());      //输出是1
}

    static void test1(ArrayList al)
     {
       al=null;
}
static void test2(ArrayList al)
{
   al.add("all");
}
}


·北大青鸟JAVA面试题(04-24)
·Java程序员面试宝典:super类 (04-19)
·微软101道经典面试题 (03-24)
·一些著名的大公司面试题目 (02-03)
·JAVA笔试改错题 (02-03)
·google的一道JAVA面试题(02-03)
·java程序员面试题(基础) (01-02)
·JAVA程序员面试32问(必备)(01-02)
·面试风云:与顶级CTO交手的难忘经验 (01-02)
·硅谷招聘流行搞怪试题 Google面试题答(01-02)
·java面试题 (01-01)
·IT开发工程师的悲哀 (12-28)
复制地址发给您的好友: [推荐文章] [返回顶部] [关闭窗口]
版权所有 Java大本营 1999-2007 转载请注明出处