⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mockcert02.txt

📁 JAVA方面的一道练习试题 很好的 很不错的
💻 TXT
📖 第 1 页 / 共 5 页
字号:
Question 1
===========================================================
Given the following code:

public class Test {

?
}


Which of the following can be used to define a constructor for this class:

Mutiple: 
1) public void Test() {厎
2) public Test() {厎
3) public static Test() {厎
4) public static void Test() {厎


Question 2
===========================================================
Which of the following are acceptable to the Java compiler:

Mutiple: 
1) if (2 == 3) System.out.println("Hi");
2) if (2 = 3) System.out.println("Hi");
3) if (true) System.out.println("Hi");
4) if (2 != 3) System.out.println("Hi");
5) if (aString.equals("hello")) System.out.println("Hi");


Question 3
===========================================================
Assuming a method contains code which may raise an Exception (but not a RuntimeException), what is the correct way for a method to indicate that it expects the caller to handle that exception:

Mutiple: 
1) throw Exception
2) throws Exception
3) new Exception
4) Don't need to specify anything


Question 4
===========================================================
What is the result of executing the following code, using the parameters 4 and 0:

public void divide(int a, int b) {
  try {
      int c = a / b;
  }catch (Exception e) {
      System.out.print("Exception ");
  }finally {
      System.out.println("Finally");
  }
}

Mutiple: 
1) Prints out: Exception Finally
2) Prints out: Finally
3) Prints out: Exception
4) No output


Question 5
===========================================================
Which of the following is a legal return type of a method overloading the following method:

public void add(int a) {厎

Mutiple: 
1) void
2) int
3) Can be anything


Question 6
===========================================================
Which of the following statements is correct for a method which is overriding the following method:


public void add(int a) {厎

Mutiple: 
1) the overriding method must return void
2) the overriding method must return int
3) the overriding method can return whatever it likes


Question 7
===========================================================
Given the following classes defined in separate files:

class Vehicle {
  public void drive() {
    System.out.println("Vehicle: drive");
  }
}

class Car extends Vehicle {
  public void drive() {
    System.out.println("Car: drive");
  }
}

public class Test {
  public static void main (String args []) {
    Vehicle v;
    Car c;

    v = new Vehicle();
    c = new Car();
    v.drive();
    c.drive();
    v = c;
    v.drive();
  }
}

What will be the effect of compiling and running this class Test?

Only One: 
1) Generates a Compiler error on the statement v= c;
2) Generates runtime error on the statement v= c;
3) Vehicle: drive
Car: drive
Car: drive
4) Vehicle: drive
Car: drive
Vehicle: drive


Question 8
===========================================================
Where in a constructor, can you place a call to a constructor defined in the super class?

Mutiple: 
1) Anywhere
2) The first statement in the constructor
3) The last statement in the constructor
4) You can't call super in a constructor


Question 9
===========================================================
Which variables can an inner class access from the class which encapsulates it?

Mutiple: 
1) All static variables
2) All final variables
3) All instance variables
4) Only final instance variables
5) Only final static variables


Question 10
===========================================================
What class must an inner class extend:

Mutiple: 
1) The top level class
2) The Object class
3) Any class or interface
4) It must extend an interface


Question 11
===========================================================
In the following code, which is the earliest statement, where the object originally held in e, may be garbage collected:

  1.public class Test { 
  2.  public static void main (String args []) { 
  3.    Employee e = new Employee("Bob", 48); 
  4.    e.calculatePay(); 
  5.    System.out.println(e.printDetails()); 
  6.    e = null; 
  7.    e = new Employee("Denise", 36); 
  8.    e.calculatePay(); 
  9.    System.out.println(e.printDetails()); 
 10.  } 
 11.}

Only One: 
1) Line 10
2) Line 11
3) Line 7
4) Line 8
5) Never


Question 12
===========================================================
What is the name of the interface that can be used to define a class that can execute within its own thread?

Mutiple: 
1) Runnable
2) Run
3) Threadable
4) Thread
5) Executable


Question 13
===========================================================
What is the name of the method used to schedule a thread for execution?

Mutiple: 
1) init();
2) start();
3) run();
4) resume();
5) sleep();


Question 14
===========================================================
Which methods may cause a thread to stop executing?

Mutiple: 
1) sleep()
2) stop()
3) yield()
4) wait();
5) synchronized()


Question 15
===========================================================
The following code defines a simple applet:

import java.applet.Applet;
import java.awt.*;

public class Sample extends Applet {
  private String text = "Hello World";
  public void init() {
    add(new Label(text));
  }

  public Sample (String string) {
    text = string;
  }
}

It is accessed form the following HTML page:
<html>
<title>Sample Applet</title>
<body>
<applet code="Sample.class" width=200 height=200></applet>
</body>
</html>

What is the result of compiling and running this applet:

Only One: 
1) Prints "Hello World".
2) Generates a runtime error.
3) Does nothing.
4) Generates a compile time error.


Question 16
===========================================================
Which of the following methods are defined on the Graphics class:

Mutiple: 
1) drawLine(int, int, int, int)
2) drawImage(Image, int, int, ImageObserver)
3) drawString(String, int, int)
4) add(Component);
5) setVisible(boolean);


Question 17
===========================================================
Which of the following layout managers honours the preferred size of a component:

Only One: 
1) CardLayout
2) FlowLayout
3) BorderLayout
4) GridLayout


Question 18
===========================================================
Given the following code what is the effect of a being 5:

public class Test {
  public void add(int a) {
    loop:
    for(int i = 1; i < 3; i++){
       for(int j = 1; j < 3; j++) {
          if(a == 5) {
            break loop;
          }
          System.out.println(i * j);
        }
    }
  }
}

Only One: 
1) Generate a runtime error
2) Throw an ArrayIndexOutOfBoundsException
3) Print the values: 1, 2, 2, 4
4) Produces no output


Question 19
===========================================================
What is the effect of issuing a wait() method on an object

Mutiple: 
1) If a notify() method has already been sent to that object then it has no effect
2) The object issuing the call to wait() will halt until another object sends a notify() or notifyAll() method
3) An exception will be raised
4) The object issuing the call to wait() will be automatically synchronized with any other objects using the receiving object.


Question 20
===========================================================
The layout of a container can be altered using which of the following methods:

Mutiple: 
1) setLayout(aLayoutManager);
2) addLayout(aLayoutManager);
3) layout(aLayoutManager);
4) setLayoutManager(aLayoutManager);


Question 21
===========================================================
Using a FlowLayout manager, which is the correct way to add elements to a container:

Mutiple: 
1) add(component);
2) add("Center", component);
3) add(x, y, component);
4) set(component);


Question 22
===========================================================
Given that a Button can generate an ActionEvent which listener would you expect to have to implement, in a class which would handle this event?

Mutiple: 
1) FocusListener
2) ComponentListener
3) WindowListener
4) ActionListener
5) ItemListener


Question 23
===========================================================
Which of the following, are valid return types, for listener methods:

Only One: 
1) boolean
2) the type of event handled
3) void
4) Component


Question 24
===========================================================
Assuming we have a class which implements the ActionListener interface, which method should be used to register this with a Button?

Only One: 
1) addListener(*);
2) addActionListener(*);
3) addButtonListener(*);
4) setListener(*);


Question 25
===========================================================
In order to cause the paint(Graphics) method to execute, which of the following is the most appropriate method to call:

Mutiple: 
1) paint()
2) repaint()
3) paint(Graphics)
4) update(Graphics)
5) None ?you should never cause paint(Graphics) to execute


Question 26
===========================================================
Which of the following illustrates the correct way to pass a parameter into an applet:

Only One: 
1) <applet code=Test.class age=33 width=100 height=100>
2) <param name=age value=33>
3) <applet code=Test.class name=age value=33 width=100 height=100>
4) <applet Test 33>


Question 27
===========================================================
Which of the following correctly illustrate how an InputStreamReader can be created:

Mutiple: 
1) new InputStreamReader(new FileInputStream("data"));
2) new InputStreamReader(new FileReader("data"));
3) new InputStreamReader(new BufferedReader("data"));
4) new InputStreamReader("data");
5) new InputStreamReader(System.in);


Question 28
===========================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -