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

📄 tt.html

📁 详细介绍scjp考试指南包括基础语法和文件读取
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<br><br>
1.   class A extends Integer {
<br><br>
2.      int x = 0;
<br><br>
3.   }
<br><br>
a.  The code will compile correctly.
<br><br>
b.  The code will not compile because Integer class is final.
<br><br>
c.  The code will not compile because A class doesn't have a constructor.
<br><br>
d.  The code will compile but an ArithmeticException at runtime.
<br><br>

<br><br>

<br><br>
Q49
<br><br>
FlowLayout is the default layout manager for which of the following containers. Select all valid answers?
<br><br>
a.  Panel
<br><br>
b.  Applet
<br><br>
c.  Frame
<br><br>
d.  Dialog
<br><br>

<br><br>
Q50
<br><br>
Using a FlowLayout Manager, which of the following is the correct way to add a component reference by the variable "c" to a container.
<br><br>
a.  add(c)
<br><br>
b.  c.add()
<br><br>
c.  add("Center",c)
<br><br>
d.  set(c)
<br><br>

<br><br>

<br><br>
Q51
<br><br>
Given the following code snippet
<br><br>

<br><br>
1.   class A {
<br><br>
2.     public void method(int a, float b) { 
<br><br>
3.         // some declaration and etc. 
<br><br>
4.     } 
<br><br>
5.   } 
<br><br>

<br><br>
6.    public class B extends A { 
<br><br>
7.      //Comment here ?
<br><br>
8.    } 
<br><br>

<br><br>
In class B what all methods can be placed in (// Comment here ?) individually ? 
<br><br>
a. void method(int i, float a) 
<br><br>
b. public void method(int i, float f) 
<br><br>
c  public void method() 
<br><br>
d. protected int method(float f, int b) 
<br><br>

<br><br>
Q52
<br><br>
What does the following program do when it is run with the following command?
<br><br>

<br><br>
   java Mystery Mighty Mouse
<br><br>

<br><br>
 1.   class Mystery {
<br><br>
 2.      public static void main(String args[]) {
<br><br>
 3.        Changer c = new Changer();
<br><br>
 4.        c.method(args);
<br><br>
 5.        System.out.println(args[0] + " " + args[1]);
<br><br>
 6.      }
<br><br>

<br><br>
 7.      static class Changer {
<br><br>
 8.        void method(String s[]) {
<br><br>
 9.         String temp = s[0];
<br><br>
10.         s[0] = s[1];
<br><br>
11.         s[1] = temp;
<br><br>
12.       }
<br><br>
13.     }
<br><br>
14.   }
<br><br>

<br><br>
a.  The program causes and ArrayIndexOutOfBoundsException to be thrown.
<br><br>
b.  The program runs but does not write anything to the standard output.
<br><br>
c.  The program writes "Mighty Mouse" to the standard output.
<br><br>
d.  The program writes "Mouse Mighty" to the standard output.
<br><br>

<br><br>
Q53
<br><br>
What happens when you try to compile and run the following program?
<br><br>

<br><br>
 1.   class Mystery {
<br><br>
 2.     String s;
<br><br>
 3.     public static void main(String args[]) {
<br><br>
 4.       Mystery m = new Mystery();
<br><br>
 5.       m.go();
<br><br>
 6.     }
<br><br>

<br><br>
 7.     void Mystery() {
<br><br>
 8.       s = "Constructor";
<br><br>
 9.     }
<br><br>

<br><br>
10.     void go() {
<br><br>
11.       System.out.println(s);
<br><br>
12.     }
<br><br>
13.   }
<br><br>

<br><br>
a. The code compiles and throws an exception at run time.
<br><br>
b. The code runs, but nothing appears in the standard output.
<br><br>
c. The code runs, and "constructor" appears in the standard output.
<br><br>
d. The code runs and writes "null" in the standard output.
<br><br>

<br><br>

<br><br>
Q54
<br><br>
What can you write at the comment //A in the following code so that this program writes the word "running" to the standard output?
<br><br>

<br><br>
 1.   class RunTest implements Runnable {
<br><br>
 2.     public static void main(String args[]) {
<br><br>
 3.       RunTest rt = new RunTest();
<br><br>
 4.       Thread t = new Thread(rt);
<br><br>
 5.       //A
<br><br>
 6.     }
<br><br>

<br><br>
 7.     public void run() {
<br><br>
 8.       System.out.println("running");
<br><br>
 9.     }
<br><br>

<br><br>
10.     void go() {
<br><br>
11.       start(1);
<br><br>
12.     }
<br><br>

<br><br>
13.     void start(int i) {
<br><br>
14.     }
<br><br>
15.   } 
<br><br>

<br><br>
Select all valid answers.
<br><br>
a.  System.out.println("running");
<br><br>
b.  t.start();
<br><br>
c.  rt.start();
<br><br>
d.  rt.start(1);
<br><br>

<br><br>
Q55
<br><br>
What is wrong with the following code?
<br><br>
1.   final class First {
<br><br>
2.     private int a = 1;
<br><br>
3.     int b = 2;
<br><br>
4.   }
<br><br>

<br><br>
5.   class Second extends First {
<br><br>
6.     public void method() {
<br><br>
7.       System.out.println(a+b);
<br><br>
8.     }
<br><br>
9.   }
<br><br>

<br><br>
a. You cannot invoke println() without passing it a string.
<br><br>
b. Because a is private, no classes other than First can access it.
<br><br>
c. Second cannot extend First.
<br><br>
d. final is not a valid keyword for a class.
<br><br>

<br><br>
Q56
<br><br>
What is displayed when the following piece of code is executed.
<br><br>

<br><br>
 1.    class Test extends Thread {
<br><br>
 2.      public void run() {
<br><br>
 3.        System.out.print("1 ");
<br><br>
 4.        yield();
<br><br>
 5.        System.out.print("2 ");
<br><br>
 6.        suspend();
<br><br>
 7.        System.out.print("3 ");
<br><br>
 8.        resume();
<br><br>
 9.        System.out.print("4 ");
<br><br>
10.      }
<br><br>

<br><br>
11       public static void main(String []args) {
<br><br>
12.        Test t = new Test();
<br><br>
13.        t.start();
<br><br>
14.      }
<br><br>
15.    }
<br><br>

<br><br>
a.  Nothing, this is not a valid way to create and start a thread.
<br><br>
b.  1 2
<br><br>
c.  1 2 3
<br><br>
d.  1
<br><br>

<br><br>
Q57
<br><br>
What must be true for the RunHandler class so that the instances of RunHandler can be used as written in the following code?
<br><br>

<br><br>
1.   class Test {
<br><br>
2.     public static void main(String args[]) {
<br><br>
3.       Thread t = new Thread(new RunHandler());
<br><br>
4.       t.start();
<br><br>
5.     }
<br><br>
6.   }
<br><br>

<br><br>
Select all valid answers ?
<br><br>
a.  RunHandler must only implement the java.lang.Runnable interface.
<br><br>
b.  RunHandler must only extend the Thread class.
<br><br>
c.  RunHandler must extend the Thread class or implement Runnable interface.
<br><br>
d.  RunHandler must provide a run() method declared as public and returning void.
<br><br>

<br><br>
Q58
<br><br>
Which interface implementations can you add as listeners for a TextField object? Select all valid answers.
<br><br>
a.  ActionListener
<br><br>
b.  FocusListener
<br><br>
c.  MouseMotionListener
<br><br>
d.  ContainerListener
<br><br>

<br><br>
Q59
<br><br>
Which statements accurately describe the following line of code?
<br><br>

<br><br>
     String s[][] = new String[10][];
<br><br>

<br><br>
Select all valid answers.
<br><br>
a.  This line of code is illegal.
<br><br>
b.  s is a two dimensional array containing 10 rows and 10 columns.
<br><br>
c.  s is an array of 10 arrays.
<br><br>
d.  Each element in s is set to "".
<br><br>

<br><br>
Q60
<br><br>
To force a layout manager to re-layout the components in a container, you can invoke the container method called
<br><br>
a.  validate()
<br><br>
b.  repaint()
<br><br>
c.  layout()
<br><br>
d.  update();
<br><br>

<br><br>
Q61
<br><br>
You need a container to hold six equal-sized button in the three columns of two. This arrangement must persist when the container is resized. Which of the following will create the that container? 
<br><br>
a. Canvas c = new Canvas(new GridLayout(2,3));
<br><br>
b. Panel p = new Panel(new GridLayout(2,3));
<br><br>
c. Window w = new Window(new GridLayout(2,3));
<br><br>
d. Panel p = new Panel(new GridLayout(3,2));
<br><br>

<br><br>
Q62
<br><br>
The following lists the complete contents of the file named Derived.java
<br><br>

<br><br>
  1. public class Base extends Object {
<br><br>
  2.   String objType;
<br><br>
  3.   public Base() { objType = "I am a Base type"  ; }
<br><br>
  4. }
<br><br>

<br><br>
  5. public class Derived extends Base {
<br><br>
  6.   public Dervied() { objType = "I am a Dervied type"; }
<br><br>

<br><br>
  8.   public static void main(String args[]) {
<br><br>
  9.     Dervied d = new Derived();
<br><br>
 10.   }
<br><br>
 11. }
<br><br>

<br><br>
What will happen when this file is compiled?
<br><br>
a. Two class files,Base.class and Dervied.class, will be created.
<br><br>
b. The compiler will object to line 1.
<br><br>
d. The compiler will object to line 2.
<br><br>
c. The compiler will object to line 5.
<br><br>

<br><br>
Q63
<br><br>
Your mouseDragged() event handler and your paint method look like this	
<br><br>

<br><br>
  1. public void mouseDragged(MouseEvent e) {
<br><br>
  2.   mouseX = e.getX();
<br><br>
  3.   mouseY = e.getY();
<br><br>
  4.   repaint();
<br><br>
  5. }
<br><br>

<br><br>
  6. public void paint(Graphics g) {
<br><br>
  7.   g.setColor(Color.cyan);
<br><br>
  8.   g.drawLine(mouseX,mouseY,mouseX+10,mouseY+10);
<br><br>
  9. }
<br><br>

<br><br>
You want to modify your code so that the cyan lines accumulate on the screen, rather than getting erased every time repaint() calls update(). What is the simplest way to proceed?
<br><br>
a. On line 4, replace repaint() with paint().
<br><br>
b. On line 4, replace repaint() with update().
<br><br>
c. After line 7, add this super.update(g);
<br><br>
d. Add public void update(Graphics g) { paint(g); }
<br><br>

<br><br>

<br><br>
Q64
<br><br>
Given the following code for the Demo class		
<br><br>

<br><br>
  1. public class Demo {
<br><br>
  2.   private String [] userNames;
<br><br>

<br><br>
  3.   public Demo() { 
<br><br>
  4.     userNames = new String[10];
<br><br>
  5.   }
<br><br>

<br><br>
  6.   public void showName(int n) {
<br><br>
  7.     System.out.println("Name is " + userNames[n]);
<br><br>
  8.    }
<br><br>
  9. 
<br><br>
 10.   public String getName(int n) {
<br><br>
 11.     return(userNames[n]);
<br><br>
 12.   }
<br><br>
 13. }
<br><br>

<br><br>
What would be the result of calling the showName method with a parameter of 2 immediately after creating an instance of Demo
<br><br>

<br><br>
a. Standard output would show "Name is null".
<br><br>
b. A NullPointerException would be thrown, halting the program.
<br><br>
c. An ArrayIndexOutOfBoundsException would be thrown halting the program.
<br><br>
d. Standard output would show "Name is".
<br><br>

<br><br>
Q65
<br><br>
What will be the result of attempting to compile and run the following class?	
<br><br>

<br><br>
 1. public class Integers {
<br><br>
 2.   public static void main(String args[]) {
<br><br>
 3.     System.out.printl(0x10 + 10 + 010);
<br><br>
 4.   } 
<br><br>
 5. }
<br><br>

<br><br>
Select the one right answer.
<br><br>
a. The code won't compile. The compiler will complain about the expression 0x10 + 10 + 010
<br><br>
b. When run, the program will print "28"
<br><br>
c. When run, the program will print "34"
<br><br>
d. When run, the program will print "36"
<br><br>

<br><br>

<br><br>
Q66
<br><br>
How will the following program lay out its buttons?	
<br><br>

<br><br>
  1. import java.awt.*;
<br><br>

<br><br>
  2. public class MyClass {
<br><br>
  3.   public static void main(String args[]) {
<br><br>
  4.     String labels[] = {"A","B","C","D","E","F"};

⌨️ 快捷键说明

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