1:下面关于变量及其范围的陈述哪些是错的。 A.实例变量是类的成员变量。 B.实例变量用关键字static声明。 C.在方法中定义的局部变量在该方法被执行时创建 D.局部变量在使用前必须被初始化。
2:Which of the following statements are not legal?
A.long l = 4990; B.int i = 4L; C.double d = 34.4; D.double t = 0.9F.
3: What results from attempting to compile and run the following code?
public class Ternary
{
public static void main(String args[])
{
int a = 5;
System.out.println("Value is - " + ((a < 5) ? 9.9 : 9));
}
}
Choices:
A.prints: Value is - 9 B.Compilation error C. prints: Value is - 5 D.None of these
4: Consider the class hierarchy shown below:
--------------------------------------------------------------------
class FourWheeler implements DrivingUtilities
class Car extends FourWheeler
class Truck extends FourWheeler
class Bus extends FourWheeler
class Crane extends FourWheeler
----------------------------------------------------------------------
Consider the following code below:
1.DrivingUtilities du;
2.FourWheeler fw;
3.Truck myTruck = new Truck();
4.du = (DrivingUtilities)myTruck;
5.fw = new Crane();
6.fw = du;
Which of the statements below are true?
Choices: A.Line 4 will not compile because an interface cannot refer to an object. B.The code will compile and run. C.The code will not compile without an explicit cast at line 6, because going down the hierarchy without casting is not allowed. D.The code will compile if we put an explicit cast at line 6 but will throw an exception at runtime.
5:以下的C程序代码片段运行后C和d的值分别是多少 Int a =1,b =2; Int c,d; c =(a&b)&&a; d =(a&&b)&a;
A.0,0 B.0,1 C.1,0 D.1,1
6: What will happen when you attempt to compile and run the following code?
class Base
{
int i = 99;
public void amethod()
{
System.out.println("Base.amethod()");
}
Base()
{
amethod();
}
}
public class Derived extends Base
{
int i = -1;
public static void main(String argv[])
{
Base b = new Derived();
System.out.println(b.i);
b.amethod();
}
public void amethod()
{
System.out.println("Derived.amethod()");
}
}
Choices: A.Derived.amethod() -1 Derived.amethod() B.Derived.amethod() 99 C.Compile time error D.Derived.amethod()
7: What is the result when you compile and run the following code?
public class ThrowsDemo
{
static void throwMethod()
{
System.out.println("Inside throwMethod.");
throw new IllegalAccessException("demo");
}
public static void main(String args[])
{
try
{
throwMethod();
}
catch (IllegalAccessException e)
{
System.out.println("Caught " + e);
}
}
}
Choices:
A.Compilation error B.Runtime error C.Compile successfully, nothing is printed. D.Inside throwMethod. followed by caught:java.lang.IllegalAccessExcption: demo
8: 1. public class X { 2. public object m () { 3. object o = new float (3.14F); 4. object [] oa = new object [1]; 5. oa[0]= o; 6. o = null; 7. oa[0] = null; 8.return o; 9. } 10.} When is the float object created in line 3, eligible for garbage collection? A.Just after line 5 B.Just after line 6 C.Just after line 7 D.Just after line 8(that is, as the method returns)
9: Give the code fragment: if(x>4){ System.out.println(“Test 1”);} else if (x>9){ System.out.println(“Test 2”);} else { System.out.println(“Test 3”);} Which range of value x would produce of output “Test 2”? A.x<4 B.x>4 C.x>9 D.None
10:Which code fragments would correctly identify the number of arguments passed via command line to a Java application, exclude the name of the class that is being invoke. A.int count = args.length; B.int count = args.length-1; C.int count=0; while(args[count]!=null) count++; D.int count=0;while (!(args[count].equals(“”))) count++;
11: public class OuterClass { private double d1 = 1.0; //insert code here } You need to insert an inner class declaration at line 3. Which two inner class declarations are valid? 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;} }
12:Which statement about listener is true? A.Most component allow multiple listeners to be added. B.If multiple listener be add to a single component, the event only affected one listener. C.Component don?t allow multiple listeners to be add. D.none
13: Give the following method: public void method( ){ String a,b; a=new String(“hello world”); b=new String(“game over”); System.out.println(a+b+”ok”); a=null; a=b; System.out.println(a); } In the absence of compiler optimization, which is the earliest point the object a refered is definitely elibile to be garbage collection. A.before line 5 B.before line 6 C.before line 7 D.before line 9
14:设有变量说明语句int a=1,b=0; 则执行以下程序段的输出结果为( )。 switch (a) { case 1: switch (b) { case 0:printf("**0**");break; case 1:printf("**1**");break; } case 2:printf("**2**");break; } printf("\n"); A.**0** B.**0****2** C.**0****1****2** D.有语法错误
15:Which is the main() method return of a application? A.String B.byte C.char D.void
简答题 16:100位以上的超大整数的加法(主要考虑数据结构和加法的实现)。
17:Static Inner Class 和 Inner Class的不同,说得越多越好。
18: class Something { int I; public void doSomething() { System.out.println("I = " + i); } } 代码是否有错?为什么。
19:对象流只能读/写对象吗?还能读/写其它数据吗?为什么?
20:整数转换为字符串。
21:请阐述一下你对“面向接口编程”的理解。
22: abstract class Something { private abstract String doSomething (); } 分析上面的代码,正确还是错误。并说明原因。
23:公元4046年,人类科学高度发达,绝大部分人都已经移居至浩瀚的宇宙,在上千颗可居住的星球上留下了人类的印记。然而,此时人类却分裂成了两个联盟:正义联盟和邪恶联盟。两个联盟之间仇恨难解,时有战争。
现在,邪恶联盟通过不正当贸易积聚了大量宇宙财富。因此,正义联盟计划要破坏邪恶联盟的非法贸易网络,从而影响邪恶联盟的经济状况,为下一次战争作好准备。邪恶联盟由数百颗星球组成,贸易通过星球间的运输航道来完成。一条运输航道是双向的且仅连接两个星球,但两个星球之间可以有多条航道,也可能没有。两个星球之间只要有运输航道直接或间接的相连就可以进行贸易。正义联盟计划破坏邪恶联盟中的一些运输航道,使得邪恶联盟的星球分成两部分,任一部分的星球都不能与另一部分的星球进行贸易。但是为了节省破坏行动所需的开支,正义联盟希望破坏尽量少的运输航道来达成目标。请问正义联盟最少需要破坏多少条运输航道呢?
24:统计一个字符串中字符出现的次数。文章来源:笔试网 www.—专业的笔试、面试资料搜索网站
|