A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 张涛的狂怒 中级黑马   /  2014-8-4 23:07  /  1396 人查看  /  15 人回复  /   2 人收藏 转载请遵从CC协议 禁止商业使用本文

一、 写出下面代码的执行结果    (分值10分)
public class Foo {
public static void main(String[] args) {
  String strValue="ABCDEFG";
  strValue.substring(3);
  strValue.concat("123");
  System.out.println("result=" + strValue);//ABCDEFG
  
  String value = new String ("ABCDEFG");
  System.out.println(strValue== value);//false
}
}
二、 写出下面代码的执行结果
public class Foo{  (分值5分)
public static void main(String args[]) {
  int x = 100;
  int y = 200;
  if (x = y)//=是赋值运算符。不是比较运算符。 编译失败。
   System.out.println("Not equal");
  else
   System.out.println("Equal");
}
}


三、 写出下面代码的执行结果 (此题需写出分析过程,没有分析过程不得分,分值10分)
import java.io.IOException;
public class ExceptionTest {
public static void main(String args[]) {
  try {
   new ExceptionTest().methodA(5);
  } catch (IOException e) {
   System.out.println("caught IOException");
  } catch (Exception e) {
   System.out.println("caught Exception");
  }finally{
   System.out.println("no Exception");
}
}
void methodA(int i) throws IOException {
  if (i%2 != 0)
   throw new IOException("methodA IOException");
}
}
在主函数中建立本类对象,调用了非静态方法methodA(5);
methodA方法执行方法体时,因为条件满足,抛出了IO异常。
Try就检测到了该异常。
因为有多个catch,会去找匹配的第一个catch。所以catch(IOException e){}就执行了。打印caught IOException。异常被处理后。在执行finally代码块中的语句。
因为finally中的代码一定会执行。Finally代码块通常都用于关闭资源。比如流资源,或者数据库。

四、 写出下面代码执行的结果(此题需写出分析过程,没有分析过程不得分,分值10分)
public class Test {
static boolean isTrue() {
  System.out.println("isTrue");
  return true;
}
static boolean isFalse() {
  System.out.println("isFalse");
  return false;
}
public static void main(String[] args) {
  if (isTrue() || isFalse()) {
   System.out.println(" || operate return true");
  }
  if (isFalse() & isTrue()) {
   System.out.println(" & operate return true");
  }
}
}

五、 写出下面代码执行的结果(此题需写出分析过程,没有分析过程不得分,分值10分)
class MyThread extends Thread{
public void run(){
  try {
   Thread.currentThread().sleep(3000);
  } catch (InterruptedException e) {
  }
  System.out.println("MyThread running");
}
}

public class ThreadTest{
public static void main(String argv[]) {
  MyThread t = new MyThread();
  t.run();
  t.start();
  System.out.println("Thread Test");
   }
}
六、 执行B.main的结果是什么?(此题需写出分析过程,没有分析过程不得分,分值10分)
class A {
  void fun1() {
    System.out.println(this.fun2());
  }
  int fun2() {
    return 123;
  }
}
class B extends A {
  int fun2() {
    return 456;
  }
  public static void main(String argv[]) {
    A a;
    B b = new B();
    b.fun1();
    a = b;
    a.fun1();
  }
}

七、 执行ListTest.main的结果是什么?(此题需写出分析过程,没有分析过程不得分,分值10分)
class Data {
int val;
int getVal() {
  return val;
}
void setVal(int val) {
  this.val = val;
}
}
public class ListTest {
  public static void main(String argv[]) {
   Data data = new Data();
   ArrayList list = new ArrayList();
   for (int i=100; i<103; i++) {
            data.setVal(i);
            list.add(data);
          }
        int j = 0;
        while (j < list.size()) {
          Data tmp = (Data )list.get(j);
          System.out.println("list(" + j + ") = " + tmp.getVal());
          j++;
        }
  }
}


八、 请指出以下代码有哪些错误(分值15分)
1.
abstract class Name {
   private String name;
   public abstract boolean isStupidName(String name) {}
}
2.
public class Something {
   void doSomething () {
       private String s = "";
       int l = s.length();
   }
}
3.
public class Something {
   public int addOne(final int x) {
       return ++x;
   }
}

九、 写出以下正则表达式(分值10分)
1-6位字母或数字:
手机号(只能以139或159开通,11位数字):
十、 写一个方法,实现字符串的反转,如:输入abc,输出cba(分值10分)
     

十一、 写一个延迟加载的单例模式(Singleton)的例子(分值10分)

十二、
public class OuterClass {
  private double d1 = 1.0;
    //insert code here
}
把下列答案存放在指定code位置上,哪两个答案是正确的。阐述原因。
A. class InnerOne{
     public static double methoda() {return d1;}
   }
B. public class InnerOne{
     static double methoda() {return d1;}
   }
C. private class InnerOne{
     double methoda() {return d1;}
   }
D. static class InnerOne{
     protected double methoda() {return d1;}
   }
E. abstract class InnerOne{
     public abstract double methoda();
   }

评分

参与人数 1技术分 +1 收起 理由
格子、 + 1 赞一个!

查看全部评分

15 个回复

倒序浏览
学习了      
回复 使用道具 举报
多谢分享
回复 使用道具 举报
这个是好东西啊,赶紧收藏
回复 使用道具 举报
果断拿走了!
回复 使用道具 举报
谢谢搂主
回复 使用道具 举报
楼主,是好样的。
回复 使用道具 举报
感谢楼主,谢谢分享
回复 使用道具 举报
多谢多谢
回复 使用道具 举报
谢谢分享呀
回复 使用道具 举报
先标记下来吧
回复 使用道具 举报
看看~~~~~~~~~~~~~~~~~~~~~
回复 使用道具 举报
Ron 中级黑马 2014-8-5 22:29:24
13#
复制下来研究下
回复 使用道具 举报
看的我头大
回复 使用道具 举报
谢谢啊,复制一下:D
回复 使用道具 举报
一顿一只牛 来自手机 中级黑马 2014-8-6 00:49:43
16#
看得头都晕了呀。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马