我是靠谱客的博主 义气冥王星,最近开发中收集的这篇文章主要介绍试题,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

I. True or False(10%)
1.char of Java is 8-bit
2.A Java class can extend from multiple base classes.
3.Member variables is to get a default init value when the object is to be created.
4.InputStream and OutputStream read write 8-bit data.
5.protected member can be visited by extended class only.
6.It is possible to create a thread by extending the Thread class.
7.length of an array is the number of elements in the array.
8.Arrays in Java can change its size as needed.
9.All methods are run-time dynamic binding.
10.When a class implements an interface, it can define as many methods of the interface as needed.

II. Multiple choice (40%)
1.How much time is a thread to get the CPU back after calling sleep(1000)?
(A)Right 1000ms
(B)Less than 1000ms
©>=1000ms
(D)may great than or less than 1000ms

2.For the code below:
class Test {
private int m;
public static void fun() {
// some code…
}
}
How to let the member variable m be visited by the function fun()?
(A)Change private int m to protected int m
(B)Change private int m to public int m
©Change private int m to static int m
(D)Change private int m to int m

3.For code below:
class DataServer extends Server {
public String serverName;
public DataServer() {
serverName = “Customer Service”;
super(serverName);
}
}
Which statement is right?
A.Code can pass the compilation
B.Code can pass the compilation but a fault would happen in creating object of DataServer
C.Code can NOT pass the compilation for the error in the 2nd line
D.Code can NOT pass the compilation for the error in the 5th line

  1. For the code below:
    public class MyProgram {
    public void main() {
    try {
    System.out.println(“Hello”);
    }
    }
    }
    Which statement is right?
    A.Code can pass the compilation
    B.Code can NOT pass the compilation for the error in the 2nd line
    C.Code can NOT pass the compilation for the error in the 5th line
    D.Code can NOT pass the compilation because it does not declare any exception

  2. For the code below:
    boolean m = true;
    if ( m=false )
    System.out.println(“False”);
    else
    System.out.println(“True”);
    What is the output?
    A.False
    B.True
    C.None
    D.An error will occur when running

  3. Which word below is NOT keyword of Java?
    A.const
    B.NULL
    C.false
    D.native

  4. Object of which class below can be input value of constructor of DataInputStream?
    A.File
    B.String
    C.FilterInputStream
    D.FileOutputStream

  5. Which method below is to define a executive body of a thread?
    A.start();
    B.inti()
    C.run()
    D.synchronized()

III. Q&A (10%)
1). For a class Class1 in Class1.java as below:
package Testpackage;
public class Class1{
… …
}
The main() is in MainPro.java as below:
import Testpackage;
… …
The CLASSPATH is "c:javalibclasses.zip;.; ". The MainPro.java is in c:Testdir. The current directory is c:Testdir. Where should we put the Class1.class?

2). For code below::
Loop1:
while ( true ) { // 1
for ( ; true; ) {
if ( i ==2 )
break Loop1; // 2
}
i=4; // 3
}
i=5; // 4
After executing line 2, where will the program jump to?

IV. Write the output of the code below: (5%)
class Letter {
char c;
}
public class PassObject {
static void f(Letter y) {
y.c = ‘z’;
}

public static void main(String[] args) {
	Letter x = new Letter();
	x.c = 'a';
	f(x);
	System.out.println(x.c);
}

}

V. For code below: (8%)
public class TestClass extends Object{
private int x;
private int y;
TestClass theClass;
public TestClass(){
}
public TestClass(int x, int y){
//… … …
}
public void show(){
System.out.println("nx="+x+" y="+y);
}
public void show(boolean flag){
if (flag)
System.out.println("nx="+x+" y="+y);
else
System.out.println("ny="+y+" x="+x);
}
protected void finalize() {
super.finalize();
}
public static void main(String args[]) {
TestClass testClass;
testClass.show();
}
}

  1. Which are member variables of class TestClass?
  2. Which are constructors?
  3. The aim of method TestClass(int x, int y) is to assign the member variables x and y with the value of x and y in its parameter list. Write the body of TestClass(int x, int y)(no more than two statements).

VI、While line below is incorrect.(10%)
class Example {
string str;
public Example() {
str = “example”;
}
public Example(String s) {
str = s;
}
}
class Demo extends Example {
}
public class Test {
public void f() {
Example ex = new Example(“Good”);
Demo d = new Demo(“Good”);
}
}

VII. Write the output of the code below: (5%)
class Annoyance extends Exception {}
class Sneeze extends Annoyance {}

public class Human {
public static void main(String[] args) {
try {
throw new Sneeze();
} catch ( Sneeze s ) {
System.out.println(“Caught Sneeze”);
} catch ( Annoyance a ) {
System.out.println(“Caught Annoyance”);
}
}
}

VIII. Write the output of the code below(12%)
public class Haha{
public static void main(String args[]){
TestThreadClass testThread=new TestThreadClass();
testThread.start();
while (testThread.isAlive()){
try{
if (testThread.geti()==1)
testThread.stop();
else
Thread.currentThread().sleep(100);
}catch(InterruptedException e){
}
}
}
}
class TestThreadClass extends Thread{
private int i=0;
public void run(){
for (i=0; i < 3; i++){
System.out.println(“HA!”);
try{
sleep(100);
}catch(InterruptedException e){
}
}
}
public int geti(){
return(i);
}
}

最后

以上就是义气冥王星为你收集整理的试题的全部内容,希望文章能够帮你解决试题所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部