几道简单的面试题求解 (最好说说理由 谢谢)
1Does Java use ASCII characters or Unicode characters?
2What is an 'abstract' class? Choose only one option.
A A class with no methods.
B A class with no concrete subclasses.
C A class with at least one undefined message.
D None of above.
3Explain call by value and call by reference. Which of these two does Java support? Which of these two does C++ support?
4下列代码输出结果是多少 为什么)
import java.util.*;public class Test {
private String value = null; public Test(String v) {
value = v;
} public boolean equals(Test o) {
if (o == this)
return true;
if (o instanceof Test) {
Test test = (Test) o;
return value.equals(test.value);
}
return false;
} public static void main(String[] args) {
List list = new ArrayList();
Test test1 = new Test("object");
Test test2 = new Test("object");
Test test3 = new Test("object");
Object test4 = new Test("object");
list.add(test1); System.out.println(list.contains(test2));
System.out.println(test2.equals(test3));
System.out.println(test3.equals(test4));
}
}5Which of the following is NOT true regarding to RuntimeException?
A RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtul Machine.
B A method is not required to declare in its throws clause any subclasses of RuntimeException that might be thrown during the execution of the method but not caught.
C An RuntimeException is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.
D NullPointerException is one kind of RuntimeException.

解决方案 »

  1.   

    1.unicode
    2.D
    4.false
    true
    false
    5.C
      

  2.   

    1unicode
    2c?message是methord的笔误?
    3java只支持传值,c++都支持
      

  3.   

    to 楼上:
    没有笔误就是methods. 
    to 1楼:
    能解释一下答案么?
      

  4.   

    1.unicode
    2.C
    3.传值调用,实参和形参在内存中是指向2个不同地址的变量或者说是对象;而传址调用是相同的。JAVA只支持传值调用。C++两种都支持!
    4. 输出结果如下:
    false  //因为test2并未添加到list集合对象中,所以不包含
    true   //进入到Test类重写的equals方法,必然走向instanceof条件判断
    false  //Object和Test并不是同一种类型
    5.D
      

  5.   

    2What is an 'abstract' class? Choose only one option. 
    A A class with no methods. 
    B A class with no concrete subclasses. 
    C A class with at least one undefined message. 
    D None of above. 
    =============================================
    2.什么是抽象类?(单选)
    A.一个类没有方法
    B.一个类没有具体的子类
    C.一个类至少有一个未定义的消息(或方法)
    D.以上都不是故选D特此声明:之前我选择的C是错误的。除非C是“一个类至少有一个未定义的抽象方法”的话才是正确的。
      

  6.   

    to paullbm:
    我试了一下:一个抽象类即便一个抽象方法没有也是对的:这样也是可以的
    abstract  class ppp
    {

    }
      

  7.   

    第一个输出False是因为equals()方法并不是重写的object方法,而是自己的方法,object的equals方法的形参是
    object,而题目的是Test,所以并没有调用该类的的equals()方法而是object的方法。所以是false
    (o==null ? e==null : o.equals(e))这个是contains方法执行的代码。
    第二个输出True,很明显的按照题目的equals的执行顺序,结果是true
    第三个是假,依然是调用Object的Equals方法。
      

  8.   

    2What is an 'abstract' class? Choose only one option.
    A A class with no methods.
    B A class with no concrete subclasses.
    C A class with at least one undefined methods.
    D None of above.
    即使所有的方法都实现了,只要在类前边加上abstract她依然是抽象类 
    ——————————————————————————————————————呃,好吧,这个说的有道理,我试了一下。看来,某种程度上,abstract就是为了阻止实例化了
      

  9.   

    第三个不是调用Object的equals吧,test3是Test类型的啊。
      

  10.   


    看清楚,这个不是override的方法,是自定义的一个方法而已
      

  11.   

    不好意思 没看仔细 test4是Object类型的,我把他当test类型了
      

  12.   

    第4题第一个为什么输出false认为 解释的不对list.add(test1); 
    在这list放入的是test1   也就是"object"的内存地址
    而不是"object"本身   所以这样肯定是输出 false