SCJP考试之套题1(SCJP_104)

软件测试——实验一 一、目的和要求 (1)掌握白盒测试技术,并能应用白盒测试技术设计测试用例 (2)能用 Junit 实施测试 二、实验内容 void DoWork(int x,int y,int z){ 1 int k=0,j=0; 2 if(( x>3 ) && ( z<10 )) 3 { 4 k=xy-1; 5 j=sqrt(k); 6 } 7 if(( x= =4 ) || ( y>5 )) 8 j=xy+10; 9 j=j%3; 10 return j; 11 } 说明:程序段中每 阅读详情

1. 1)  public class ReturnIt{
 2)  returnType methodA(byte x, double y){
 3)  return (short)x/y*2;
 4)  }
 5)  }
 what is valid returnType for methodA in line 2?
Answer:double

2. 1)  class Super{
 2)  public float getNum(){return 3.0f;}
 3)  }
 4)
 5)  public class Sub extends Super{
 6)
 7)  }
which method, placed at line 6, will cause a compiler error?
A. public float getNum(){return 4.0f;}
B. public void getNum(){}
C. public void getNum(double d){}
D. public double getNum(float d){return 4.0d;}
Answer:B

3. public class IfTest{
 public static void main(String args[]){
        int x=3;
 int y=1;
 if(x=y)
 System.out.println("Not equal");
 else
 System.out.println("Equal");
 }
 }
 what is the result?
Answer:compile error

4. public class Foo{
  public static void main(String args[]){
  try{return;}
   finally{ System.out.println("Finally");}
   }
    }
 what is the result?
 A. print out nothing
 B. print out "Finally"
 C. compile error
Answer:B

5. public class Test{
  public static String output="";
   public static void foo(int i){
    try {
if(i==1){
throw new Exception();
}
output +="1";
 }
 catch(Exception e){
 output+="2";
 return;
 }
 finally{
 output+="3";
  }
 output+="4";
 }
 public static void main(String args[]){
 foo(0);
 foo(1);
 24)  
    }
    }
 what is the value of output at line 24?

Answer:13423

6. public class IfElse{
 public static void main(String args[]){
 if(odd(5))
 System.out.println("odd");
 else
 System.out.println("even");
 }
  public static int odd(int x){return x%2;}  
  }
  what is output?


Answer:Compile Error


7. class ExceptionTest{
  public static void main(String args[]){
  try{
methodA();
}
  catch(IOException e){
System.out.println("caught IOException");
  }
  catch(Exception e){
  System.out.println("caught Exception");
   }
  }
  }
 If methodA() throws a IOException, what is the result?
Answer:caught IOException
exception can catch once only
if change the sequence of catch
  catch(IOException e) can't execute  and compiler will report rongyu error


8. int i=1,j=10;
 do{
 if(i++>--j) continue;
 }while(i<5);
After Execution, what are the value for i and j?
A. i=6 j=5
B. B.i=5 j=5
C. i=6 j=4
D. i=5 j=6
E. i=6 j=6
Answer:D


9. 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;
 System.out.println(oa[0]);
 9) }
 10) }
 which line is the earliest point the object a refered is definitely elibile
 to be garbage collectioned?
 A.After line 4   B. After line 5  C.After line 6  
 D.After line 7   E.After line 9(that is,as the method returns)
Answer:D


10.    1)  interface Foo{
     2)int k=0;
     3) }
     4) public class Test implements Foo{
     5) public static void main(String args[]){
     6)int i;
     7)Test test =new Test();
     8)i=test.k;
     9)i=Test.k;
    10)i=Foo.k;
    11)     }
    12) }
   what is the result?
Answer:compile successed and i=0

11. what is reserved words in java?
  A. run
  B. default
  C. implement
  D. import
Answer:B,D

12. public class Test{
   public static void main(String[] args){
   String foo=args[1];
   Sring bar=args[2];
   String baz=args[3];
    }
    }
   java Test Red Green Blue
  what is the value of baz?
  A. baz has value of ""
  B. baz has value of null
  C. baz has value of "Red"
  D. baz has value of "Blue"
  E. baz has value of "Green"
  F. the code does not compile
  G. the program throw an exception
Answer:G

13. int index=1;
  int foo[]=new int[3];
  int bar=foo[index];
  int baz=bar+index;
  what is the result?
  A. baz has a value of 0
  B. baz has value of 1
  C. baz has value of 2
  D. an exception is thrown
  E. the code will not compile
Answer:B

14. which three are valid declaraction of a float?
   A. float foo=-1;
   B. float foo=1.0;
   C. float foo=42e1;
   D. float foo=2.02f;
   E. float foo=3.03d;
   F. float foo=0x0123;
Answer:A,D,F

15. public class Foo{
   public static void main(String args[]){
   String s;
   System.out.println("s="+s);
    }
   }
   what is the result?
Answer:compile error

16.   1) public class Test{
    2) public static void main(String args[]){
    3) int i=oxFFFFFFF1;
    4) int j=~i;
    5)
    6) }
    7) }
  which is decimal value of j at line 5?
  A. 0      B.1    C.14    D.-15    E. compile error at line 3    
  F. compile error at line 4
Answer:C

17. float f=4.2F;
  Float g=new Float(4.2F);
  Double d=new Double(4.2);
  Which are true?
  A. f==g   B. g==g   C. d==f   D. d.equals(f)  E d.equals(g)  F. g.equals(4.2);
Answer:B,E

18.  public class Test{
   public static void add3(Integer i){
 3) int val=i.intvalue();
    val+=3;
    i=new Integer(val);
    }
    public static void main(String args[]){
     Integer i=new Integer(0);
        add3(i);
     System.out.println(i.intvalue());
     }
       }
    what is the  result?
    A. compile fail       B.print out "0"      C.print out "3"  
    D.compile succeded but exception at line 3
Answer:B

19. public class Test{
    public static void main(String[] args){
     System.out.println(6^3);
     }
       }
   what is output?
Answer:5    
^ is yi huo

20. public class Test{
   public static void stringReplace(String text){
     text=text.replace('j','l');
    }
    public static void bufferReplace(StringBuffer text){
      text=text.append("c");
     }
   public static void main(String args[]){  
     String textString=new String("java");
     StringBuffer textBuffer=new StringBuffer("java");
      StringReplace(textString);
      bufferReplace(textBuffer);
    System.out.println(textString+textBuffer);
      }
      }
   what is the output?
Answer:javajavac

21. public class ConstOver{
   public ConstOver(int x, int y, int z){}
    }
   which two overload the ConstOver constructor?
   A.ConstOver(){}
   B.protected int ConstOver(){}   //not overload ,but no a error
   C.private ConstOver(int z, int y, byte x){}
   D.public void ConstOver(byte x, byte y, byte z){}
   E.public Object ConstOver(int x, int y, int z){}
Answer:A,C

22. public class MethodOver{
    public void setVar(int a, int b, float c){}
    }
   which overload the setVar?
   A.private void setVar(int a, float c, int b){}
   B.protected void setVar(int a, int b, float c){}
   C.public int setVar(int a, float c, int b){return a;}
   D.public int setVar(int a, float c){return a;}
Answer:A,C,D

23. class EnclosingOne{
  public class InsideOne{}
    }
  public class InnerTest{
   public static void main(String args[]){
   EnclosingOne eo=new EnclosingOne();
   //insert code here
   }
  }
  A.InsideOne ei=eo.new InsideOne();
  B.eo.InsideOne ei=eo.new InsideOne();
  C.InsideOne ei=EnclosingOne.new InsideOne();
  D.InsideOne ei=eo.new InsideOne();
  E.EnclosingOne.InsideOne ei=eo.new InsideOne();
Answer:E

24. What is "is a" relation?
  A.public interface Color{}
    public class Shape{private Color color;}
  B.interface Component{}
    class Container implements Component{
     private Component[] children;
      }
  C.public class Species{}
     public class Animal{private Species species;}  
  D.interface A{}
interface B{}
interface C implements A,B{}   //syntex error
Answer:B
keyword implements,entends

25. 1)package foo;
  2)
  3)public class Outer{
  4)public static class Inner{
  5)}
  6)}
  which is true to instantiated Inner class inside Outer?
  A. new Outer.Inner()
  B. new Inner()
Answer:B
if out of outerclass A is correct

26. class BaseClass{
   private float x=1.0f;
   private float getVar(){return x;}
     }
  class SubClass extends BaseClass{
   private float x=2.0f;
   //insert code
   }
  what are true to override getVar()?
  A.float getVar(){
  B.public float getVar(){
  C.public double getVar(){
  D.protected float getVar(){
  E.public float getVar(float f){
Answer:A,B,D

27. public class SychTest{
   private int x;
   private int y;
   public void setX(int i){ x=i;}
   public void setY(int i){y=i;}
   public Synchronized void setXY(int i){
     setX(i);
     setY(i);
   }
   public Synchronized boolean check(){
        return x!=y;  
   }
   }
    Under which conditions will  check() return true when called from a different class?
   A.check() can never return true.
   B.check() can return true when setXY is callled by multiple threads.
   C.check() can return true when multiple threads call setX and setY separately.
   D.check() can only return true if SychTest is changed allow x and y to be set separately.
Answer:C

28. 1)public class X implements Runnable{
  2)private int x;
  3)private int y;
  4)public static void main(String[] args){
  5)   X that =new X();
  6) (new Thread(that)).start();
  7) (new Thread(that)).start();
   }
  9) public synchronized void run(){
  10)  for(;;){
  11)      x++;
  12)      Y++;
  13) System.out.println("x="+x+",y="+y);
  14)    }
  15)   }
  16)  }  
    what is the result?
  A.compile error at line 6
  B.the program prints pairs of values for x and y that are
    always the same on the same time
Answer:B

29. class A implements Runnable{
  int i;
  public void run(){
   try{
       Thread.sleep(5000);
        i=10;
       }catch(InterruptException e){}
       }
       }
   public static void main(String[] args){
      try{
         A a=new A();
         Thread t=new Thread(a);
         t.start();
  17)
      int j=a.i;
  19)
      }catch(Exception e){}
      }
      }
  what be added at line line 17, ensure j=10 at line 19?
  A. a.wait();   B.  t.wait();   C. t.join();   D.t.yield();  
  E.t.notify();  F.  a.notify(); G.t.interrupt();
Answer:C

30. Given an ActionEvent, how to indentify the affected component?
    A.getTarget();
    B.getClass();
    C.getSource();   //public object
    D.getActionCommand();
Answer:C

31. import java.awt.*;
  public class X extends Frame{
   public static void main(String[] args){
    X x=new X();
    x.pack();
    x.setVisible(true);}
    public X(){
     setLayout(new GridLayout(2,2));
     Panel p1=new Panel();
    add(p1);
  Button b1=new Button("One");
  p1.add(b1);
  Panel p2=new Panel();
  add(p2);
  Button b2=new Button("Two");
   p2.add(b2);
  Button b3=new Button("Three");
   p2.add(b3);
  Button b4=new Button("Four");
   add(b4);
   }
    }
 when the frame is resized,
 A.all change height    B.all change width   C.Button "One" change height
 D.Button "Two" change height  E.Button "Three" change width
 F.Button "Four" change height and width
Answer:F

32. 1)public class X{
  2)    public static void main(String[] args){
  3)     String foo="ABCDE";
  4)     foo.substring(3);
  5)     foo.concat("XYZ");
  6)    }
  7)   }
  what is the value of foo at line 6?
Answer:ABCDE

33. How to calculate cosine 42 degree?
  A.double d=Math.cos(42);
  B.double d=Math.cosine(42);
  C.double d=Math.cos(Math.toRadians(42));
  D.double d=Math.cos(Math.toDegrees(42));
  E.double d=Math.toRadious(42);
Answer:C

34. public class Test{
   public static void main(String[] args){
   StringBuffer a=new StringBuffer("A");
   StringBuffer b=new StringBuffer("B");
   operate(a,b);
   System.out.pintln(a+","+b);
    }
   public static void operate(StringBuffer x, StringBuffer y){
    x.append(y);
    y=x;
   }
   }
   what is the output?
Answer:A,B

35.  1)public class Test{
   2)public static void main(String[] args){
   3) class Foo{
   4) public int i=3;
   5) }
   6)Object o=(Object)new Foo();
   7) Foo foo=(Foo)o;
   System.out.println(foo.i);
   9) }
   10) }
  what is result?
  A.compile error at line 6
  B.compile error at line 7
  C.print out 3
Answer:C

36. public class FooBar{
   public static void main(String[] args){
    int i=0,j=5;
  4) tp:  for(;;i++){
         for(;;--j)
        if(i>j)break tp;
       }
   System.out.println("i="+i+",j="+j);
   }
   }
  what is the result?
  A.i=1,j=-1    B. i=0,j=-1  C.i=1,j=4    D.i=0,j=4  
  E.compile error at line 4
Answer:B

37. public class Foo{
     public static void main(String[] args){
     try{System.exit(0);}
     finally{System.out.println("Finally");}
   }
   }
   what is the result?
   A.print out nothing
   B.print out "Finally"
Answer:A
system.exit(0) has exit


38. which four types of objects can be thrown use "throws"?
  A.Error
  B.Event
  C.Object
  D.Excption
  E.Throwable
  F.RuntimeException
Answer:A,D,E,F

39. 1)public class Test{
  2) public static void main(String[] args){
  3) unsigned byte b=0;
  4) b--;
  5)
  6) }
  7) }
  what is the value of b at line 5?
  A.-1   B.255  C.127  D.compile fail  E.compile succeeded but run error
Answer:D

40. public class ExceptionTest{
   class TestException extends Exception{}
    public void runTest() throws TestException{}
     public void test() /* point x */ {
      runTest();
      }
      }
   At point x, which code can be add on to make the code compile?
    A.throws Exception   B.catch (Exception e)
Answer:A

41. String foo="blue";
  boolean[] bar=new boolean[1];
   if(bar[0]){
      foo="green";
    }
  what is the value of foo?
   A.""  B.null  C.blue   D.green
Answer:C

42. public class X{
   public static void main(String args[]){
    Object o1=new Object();
    Object o2=o1;
    if(o1.equals(o2)){
     System.out.prinln("Equal");
      }
      }
      }
   what is result?
Answer:Equal

43. which two are equivalent?
  A.  3/2
  B.  3<2
  C.  3*4
  D.  3<<2
  E.  3*2^2
  F.  3<<<2
Answer:C,D

44. int index=1;
  String[] test=new String[3];
  String foo=test[index];
  what is the result of foo?
   A. ""   B.null    C.throw a Exception   D.not compile
Answer:B

45. public class Test{
   static void leftshift(int i, int j){
      i<<=j;
     }
   public static void main(String args[]){
      int i=4, j=2;
     leftshift(i,j);
    System.out.println(i);
     }
     }
   what is the result?
Answer:4

46. public class X{
    private static int a;
    public static void main(String[] args){
     modify(a);
     System.out.println(a);
     }
    public static void modify(int a){
      a++;
     }
     }
   what is the result?
Answer:0

47. public class Test{
   private static int j=0;
   public static boolean methodB(int k){
     j+=k;
    return true;
   }
   public static void methodA(int i){
    boolean b;
    b=i>10&methodB(1);
    b=i>10&&methodB(2);
     }
    public static void main(String args){
     methodA(0);
  17)
     }
     }
   what is the value of j at line 17?
Answer:1

48. class A{
    public String toString(){        
    return "4";
    }
    }
  class B extends A{
    public String toString(){
      return super.toString()+"3";
     }
     }
   public class Test{
      public static void main(String args){
       B b=new B();
   System.out.println(b.toString());
   }
   }
   what is the result?
Answer:43

49. class A implements Runnable{
   public int i=1;
   public void run(){
    this.i=10;
    }
    }
   public class Test{
    public static void main(String args){
     A a=new A();
   11)  new Thread(a).start();
        int j=a.i;
   13)
    }
    }
   what is the value of j at line 13?
    A. 1
    B. 10
    C. the value of j cannot be determined
    D. An error at line 11 cause compilation to fail
Answer:C

50.  public class SyncTest{
    public static void main(String[] args){
    final StringBuffer s1=new StirngBuffer();
    final StringBuffer s2=new StirngBuffer();              
    new Thread(){
     public void run(){
     Synchronized(s1){
       s1.append("A");
     Synchronized(s2){
       s2.append("B");
     System.out.print(s1);
     System.out.print(s2);
      }
      }
      }
      }.start();
    new Thread(){
     public void run(){
     Synchronized(s2){
       s2.append("C");
     Synchronized(s1){
       s1.append("D");
     System.out.print(s2);
     System.out.print(s1);
      }
      }
      }
      }.start();          
      }
      }
    what is the result?
    A.the result depends on different system and different thread model
    B.the result cannot be determined
Answer:A,B

51. public class Test{
   public static void main(String[] args){
   String foo="blue";
   String bar=foo;
   foo="green";
   System.out.println(bar);
   }
   }
   what is the result?
Answer:blue

52. which interface Hashtable implements?
  A. java.util.Map
  B. java.util.List
  C. java.util.Hashable
  D. java.util.Collection
Answer:A

53. which two are true?
  A. static inner class requires a static initializer
  B. A static inner class requires an instance of the enclosing class
  C. A static inner class has no reference to an instance of the enclosing class
  D. A static inner class has accesss to the non-static member of the other class
  E. static members of a static inner class can be referenced using the class
     name of the static inner class
Answer:C,E

54. which two are true?
  A. An anonymous inner class can be declared inside of a method
  B. An anonymous inner class constructor can take arguments in some situations
  C. An anonymous inner class that is a direct subclass of Object can implements
     multiple interface
  D. Even if a class Super does not implement any interfaces, it is still possible
     to define an anonymous inner class that is an immediate subclass of Super that
     implements a single interface
  E. Even if a class Super does not implement any interfaces, it is still possible
     to define an anonymous inner class that is an immediate subclass of Super that
     implements multipe interface
Answer:A,D

55. class A{
   public int getNumber(int a){
    return a+1;
    }
    }
     class B extends A{
  public int getNumber(int a, char c){
       return a+2;
      }
      public static void main(String[] args){
      B b=new B();
  14)  System.out.println(b.getNumber(0));
      }
      }      
   what is the result?
  A. compilation succeeds and 1 is printed
  B. compilation succeeds and 2 is printed
  C. An error at line 8 cause compilation to fail
  D. An error at line 14 cause compilation to fail
Answer:A

56.  import java.awt.*;
   public class X extends Frame{
    public static void main(String[] args){
     X x=new X();
     x.pack();
     x.setVisible(true);
     }
   public X(){
   setLayout(new BorderLayout());
   Panel p=new Panel();
   add(p,BorderLayout.NORTH);
   Button b=new Button("North");
   p.add(b);
   Button b1=new Button("South");
   add(b1,BorderLayout.SOUTH);
    }
     which two are true?
   A. The button labeled "North" and "South" will have the same width
   B. The button labeled "North" and "South" will have the same height
   C. The height of the button labeled "North" can vary if the Frame is resized
   D. The height of the button labeled "South" can vary if the Frame is resized
   E. The width of the button labeled "North" is constant even if the Frame is resized
   F. The width of the button labeled "South" is constant even if the Frame is resized
Answer:B,E

57. which two interfaces provide the capability to store objects using a key-value pair?
  A. java.util.Map
  B. java.util.Set
  C. java.util.List
  D. java.util.SortedSet
  E. java.util.SortedMap
  F. java.util.Collection
Answer:A,E

58. which two declaretions prevent the overriding of a method?
  A. final void methoda(){}
  B. void final methoda(){}
  C. static void methoda(){}
  D. static final void methoda(){}
  E. final abstract void methoda(){}
Answer:A,D

59. which two are true?
  public class OuterClass{
   private double d1=1.0;
   //inser code here
  }
  A. static class InnerOne{
      public double methoda(){return d1;}
  B. static class InnerOne{
       static double methoda(){return d1;}
  C. private class InnerOne{
      public double methoda(){return d1;}
  D. protected class InnerOne{
       static double methoda(){return d1;}
  E. public abstract class InnerOne{
     public abstract double methoda();
Answer:C,E

60. You want a class to have access to members of another class in the same
  package which is the most restrictive access modifier that will accomplish
  this objective?
  A. public
  B. private
  C. protected
  D. transient
  E. No acess modifier is required
Answer:E

61. which two statements declare an array capable of 10 ints?
  A. int[] foo;
  B. int foo[];
  C. int foo[10];
  D. Object[] foo;
  E. Object foo[10];
Answer:A,B

62. public class SwitchTest{
    public static void main(String[] args){
  3)  System.out.println("value="+switchIt(4));
   }
  public static int switchIt(int x){
     int j=1;
  switch(x){
   case 1: j++;
   case 2: j++;
   case 3: j++;
   case 4: j++;
   case 5: j++;
   default: j++;
    }
   return j+x;
   }
   }
   what is the output from line 3?
   A. value=3  B. value=4  C. value=5  D. value=6  E. value=7  F. value=8
Answer:F

63. which will declare a method that is available to all members of the same
  package and can be referenced without an instance of the class?
  A. abstract public void methoda();
  B. public abstract double methoda();
  C. static void methoda(double d1){}
  D. public native double methoda(){}
  E. protected void methoda(double d1){}
Answer:C

64. 1)public class SuperClass{
  2)  class SubClassA extends SuperClass{}
  3)  class SubClassB extends SuperClass{}
  4)  public void test(SubClassA foo){
  5)    SuperClass bar=foo;
  6)    }
  7)    }
  which statement is true about the assignment in line 5?
  A. The assignment in line 5 is illegal
  B. The assignment in line 5 is legal, but throw a ClassCastException
  C. legal and will always executes without throw an Exception      
Answer:C

65. which two are true to describe an entire encapsulation class?
   A. member data have no access modifiers
   B. member data can be modified directly
   C. the access modifier for methods is protected
   D. the access modifier to member data is private
   E. methods provide for access and modification of data
Answer:D,E

66. public class X implements Runnable{
    public static void main(String[] args){
  3)    //insert code
     }
    public void run(){
       int x=0,y=0;
       for(;;){
        x++;
        Y++;
     System.out.println("x="+x+",y="+y);
        }
       }
    }    
  which codes are added to line 3 to cause run() to be executed?
  A. X x=new X();
     x.run();
  B. X x=new X();
     new Thread(x).run();
  C. X x=new X();
     new Thread(x).start();
  D. Thread t=new Thread(x).run();
  E. Thread t=new Thread(x).start();
Answer:C(A) because run is not static

67. which gets the name of the parent directory of file "file.txt"?
   A. String name=File.getParentName("file.txt");
   B. String name=(new File("file.txt")).getParent();
   C. String name=(new File("file.txt")).getParentName();
   D. String name=(new File("file.txt")).getParentFile();
   E. Diretory dir=(new File("file.txt")).getParentDir();
      String name=dir.getName();
Answer:B

68. The file "file.txt" exists on the file system and contains ASCII text.
   try{
     File f=new File("file.txt");
     OutputStream out=new FileOutputStream(f);
     }catch (IOException e){}
   A. the code does not compile
   B. the code runs and no change is made to the file
   C. the code runs and sets the length of the file to 0
   D. An exception is thrown because the file is not closed
   E. the code runs and deletes the file from the file system
Answer:C

69.  class Super{
    public int i=0;
    public Super(String text){
    i=1;
    }
    }
    public class Sub extends Super{
      public Sub(String text){
       i=2;
      }
    public static void main(String args[]){
     Sub sub=new Sub("Hello");
     System.out.println(sub.i);
     }
     }
    what is the result?    
     A. compile will fail
     B. compile success and print "0"
     C. compile success and print "1"
     D. compile success and print "2"
Answer:A
public class sub extends super{
public sub(string text){
super(), this must be the first line.
};

70.   import java.io.IOException;
     public class ExceptionTest{
     public static void main(String args[]){
      try{
          methodA();
         }catch(IOException e){
         System.out.println("Caught Exception");
         }
         }
      public void methodA(){
       throw new IOException();
       }
       }
      what is the result?
      A.The code will not compile
      B.The output is Caught Exception
      C.The output is Caught IOException
      D.The program executes normally without printing a message
Answer:A

71.   You are assigned the task of building a Panel containing a TextArea at
    the top, a Labbel directly bellow it, and a Button directly bellow the
    Label. If the three components added directly to the Panel. which layout
    manager can the Panel use to ensure that the TextArea absorbs all of the
    free vertical space when the Panel is resized?
     A.GridLayout
     B.CardLayout
     C.FlowLayout
     D.BorderLayout
     E.GridbagLayout
Answer:E

72.  You need to store elements in a collection that guarantees that no duplicates
   are stored and all elements can be access in nature order, which interace
   provides that capability?
   A. java.uil.Map
   B.java.util.Set
   C.java.util.List
   D.java.util.SortedSet
   E.java.util.SortedMap
   F.java.util.Collection
Answer:B

73. which two cannot directly cause a thread to stop executing?
  A.calling the yield method
  B.calling the wait method on an object
  C.calling the notify method on an object
  D.calling the notifyAll method on an object  
  E.calling the start method on another thread object
Answer c,d

74. 1)public class Foo implements Runnable{
  2)  public void run(Thread t){
     System.out.println("Running");
      }
    public static void main(String[] args){
     new Thread(new Foo()).start();
     }
     }
   what is the result?
   A.An Exception is thrown
   B.The program exits without printing anything
   C.An error at line 1 causes complication to fail
   D.An error at line 2 causes complication to fail
   E."Running" is pinted and the program exits
Answer:D

75. which method in the Thread class is used to create and launch a new thread of execution?
  A.run()    B.start()   C. begin()   D.run(Runnable r)  E.execute(Thread t)
Answer:B

76. which is true?
  A.If only one thread is blocked in the wait method of an object, and another
    thread executes the notify method on that same object,then the first thread
    immediately resumes executes.
  B. If a thread is blocked in the wait method of an object, and another thread
    executes the notify method on the same object,it is still possible that the
    first thread might never resume execution
  C.If a thread is blocked in the wait method of an object,and another thread
    executes the notify method on the same object,then the first thread definitely
    resumes execution as a direct and sole consequence of the notify call
  D.If two threads are blocked in the wait method of one object,and another thread
    executes the notify method on the same object,then the thread that executed
    the wait call first definitely resumes execution as a direct and sole consequence
    of the notify call
Answer:B

77. which statement is true?
  A. An anonymous inner class may be declared as final
  B. An anonymous inner class can be declared as private
  C. An anonymous inner class can implement mutiple interfaces
  D. An anonymous inner class can access final variables in any enclosing scope
  E. Construction of an instance of a static inner class requires an instance of
     the encloing outer class
Answer:D

78.   public class X{
    public Object m(){
  3)Object o=new Float(3.14f);
    Object[] oa=new Object[1];
    Oa[0]=0;
    o=null;
    return oa[0];
    }
    }
   when is the float Object, created in line 3 ,collected as garbage?
    A.just after line 5 B.just after line 6  C.just after line 7   D.never in this method
Answer:D

79. which will declare a method that forces a subclass to implement?
  A.public double methoda()
  B.abstract public void methoda()
Answer:B    

80. //point X
  public class Foo{
  public static void main(String[] args){
  PrintWriter out=new PrintWriter(new java.io.OutputStreamWriter(System.out),true);
out.println("Hello");
}
  }
  which statement at point X on line 1 allows this code to compile and run?
  A.import java.io.PrintWriter         B.include java.io.PrintWriter
  C.import java.io.OutputStreamWriter   D.include java.io.OutputStreamWriter
  E.No statement is needed
Answer:A

81. which prevent create a subclass of outer class?
   A.static class FooBar{}
   B.pivate class Foobar{}
   C.abstract class FooBar{}
   D.final public class FooBar{}
   E.final abstract class FooBar{}
Answer:D

82.  1)abstract class AbstractIt{
   2) abstract float getFloat();
   3) }
   4) public class AbstractTest extends AbstractIt{
   5) private float f1=1.0f;
   6) private float getFloat(){return f1;}
   7) }
    A:what is the result?
    B:compile fail on line 6
Answer:B

83. byte[] array1,array2[]
  byte array3[][]
  byte[][] array4
  if each has been initialized, which statement will cause a compile error?
  A.array2=array1    B.array2=array3   C.array2=array4
Answer:A

84. what writes the text "" to the end of the file "file.txt"?
  A.OutputStream out=new FileOutputStream("file.txt");
    out.writeBytes("/n");
  B.OutputStream os=new FileOutputStream("file.txt",true);
    DataOutputStream out=new DataOutputStream(os);
    out.writeBytes("/n");
  C.OutputStream os=new FileOutputStream("file.txt");
    DataOutputStream out=new DataOutputStream(os);
    out.writeBytes("/n");
  D.OutputStream os=new OutputStream("file.txt",true);
    DataOutputStream out=new DataOutputStream(os);
    out.writeBytes("/n");
Answer:B

85. which constructs a DataOutputStream ?
  A.new DataOutputStream("out.txt");
  B.new DataOutputStream(new File("out.txt"));
  C.new DataOutputStream(new Writer("out.txt"));
  D.new DataOutputStream(new OutputStream("out.txt"));
  E.new DataOutputStream(new FileWriter("out.txt"));
  F.new DataOutputStream(new FileOutputSream("out.txt"));
Answer:F

86. which statement is true for the class java.util.HashSet?
  A.The elements in the collection are ordered
  B.The collection is guaranteeded to be immutable
  C.The elements in the collection are guaranteeded to be unique
  D.The elements in the collection are access using a unique key
  E.The elements in the collection are guaranteed to be synchronized
Answer:C

87.  1)  public abstract class Test{
    2)  public abstract void methodA();
    3)  public abstract void methodB()
    4)  { System.out.println("Hello");
    5)  }
    6)  }
   which three changes(made independently) allow the code to compile?
   A.add a method body to methodA.
   B.replace line 4-5 with a ";".
   C.remove the abstract qualifier from the declaration of  Test.
   D.remove  the abstract qualifier from the declaration of  methodB.
   E.remove  the abstract qualifier from the declaration of  methodA.
   F.remove methodB in its entirety and change class to interface in line 1.
Answer:B,D,F

88. ClassOne.java
  package com.ab.pkg1;
   public class ClassOne{
    private char var='a';
    char getVar(){ return var;}
      }
   
  ClassTest.java
   package com.ab.pkg2;
   import com.ab.pkg1.ClassOne;
    public class ClassTest extends ClassOne{
     public static void main(String args[]){
      char a=new ClassOne().getVar();
      char b=new ClassTest().getVar();
   }
   }
  what is the result?
Answer:Cimpile error

89. int i=1,j=10;
    do{
      if(i>j)continue;
      j--;
      }while(++i<6);
   what are the vale of i and j?
   A.i=6,j=5
   B.i=5,j=5
   C.i=6,j=4
   D.i=5,j=6
   E.i=6,j=6
Answer:A

90. public class Foo{
    public static void main(String[] args){
     int i=1;
     int j=i++;
     if((i>++j)&&(i++==j)){
         i+=j;
         }
         }
        }
   what is the final value i and j?
Answer:i=2,j=2    

91. which two are equivalent?
  A.16>4
  B.16/2
  C.16*4
  D.16>>2
  E.16/2^2
  F.16>>>2
Answer:D,F

92. public class X{
    public static void main(String[] args){
     byte b=127;
  4) byte c=126;
  5) byte d=b+c;
    }
    }
  A.Line 5 throws an exception indicating "out of range"
  B.Line 5 cause a compile fail
  C.compile succeeded
Answer:B

93. AnInterface is an interface
  AnAdapter0 is a non-abstract,non-final class with a zero
  argument constructer
  AnAdapter1 is a non-abstract,non-final class without a zero
  argument constructer,but with a constructer that takes one int argument
  which two create an anoymous inner class?
  A.AnAdapter0 aa=new AnAdapter0(){}
  B.AnAdapter1 aa=new AnAdapter1(5){}
  C.AnAdapter1 aa=new AnAdapter1(){}
  D.AnAdapter0 aa=new AnAdapter0(5){}    
  E.AnInterface ai=new AnInterface(5){}
Answer:A,B

94. which two create an InputStream and open the file"file.txt"
  for reading?
  A.InputStream in=new FileInputStream("file.txt");
  B.FileInputStream in=new FileInputStream(new File("file.txt"));
  C.InputStream in=new FileReader("file.txt");
Answer:A,B

95. which constructs a BufferedInputStream?
  A.new BufferedInputStream(new FileInputStream("in.txt"));
  B.new BufferedInputStream(new FileReader("in.txt"));
Answer:A
//FileReader is a char stream

96. which can be used to encode chars for output?
  A.java.io.OutputStreamWriter
  B.java.io.FileOutputStream
  C.java.io.DataOutputStream
Answer:A

97. which determines if "prefs" is a directory and exist on the file system?
  A.boolean exists=(new File("prefs")).isDirectory();
  B.boolean exists=(new File("prefs")).isDir();
Answer:A

98.which code determines the int value foo closest to, but not greater than, a double value bar?
   A.int foo=(int)Math.max(bar);
   B.int foo=(int)Math.min(bar);
   C.int foo=(int)Math.abs(bar);
   D.int foo=(int)Math.ceil(bar);
   E.int foo=(int)Math.floor(bar);
   F.int foo=(int)Math.round(bar);
Answer:E

99. import java.awt.*;
   public class Test extends Frame{
    public Test(){
      add(new Label("Hello"));
      add(new TextField("Hello"));
      add(new Button("Hello"));
      pack();   //BorderLayout  --the four area around will be lost
     show();}
   public static void main(String[] args){
    new Test();
    }
    }
  what is the result?  
Answer:center is only a button"hello"and has a window "Test"

100. which is true?
     A. Any statement that may throw an Exception must be enclosed in a try block.
//Standard Exception (Runtime Exception) is not
     B. Any statement that may throw an Error must be enclosed in a try block.
     C. Any statement that may throw an RuntimeException must be enclosed in a try block.
     D.No exception are subclass of Error.
Answer:D

101. which one is true?
      A.An anonymous class can be declared as static.
      B.A static inner class cannot be a static member of the outer class.
      C.A static inner class does not require an instance of the enclosing class.
      D.Instance member of a static inner class can be referened using the class name of the
          static inner  class.
Answer:C

102.public class MyCircle{
     public double radius;
     public double diameter;
     public void setRadius(double radious){
     6) this.radius=radius;
     7) this.diameter=radius*2;}
public double getRadius(){
return radius;}
}
  A. The MyCircle class is fullly encapsulated
  B. The diameter of a given MyCircle is guaranteed to be twice its radius.
  C. Line 6 and 7 should be in a Synchronized block to ensure encapsulation.
  D. The radius of a MyCircle object can be set without affecting its diameter.
Answer:D

103.Given:
  public class ArrayList{
   public static void main(String[] args){
   float f1[],f2[];
   f1=new float[10];
   f2=f1;
   System.out.println("f2[0]="+f2[0]);
   }
   }
   what is the result?
Answer:0.0

104.public class X{
   public static void main(String[] args){
     int[] a=new int[1];
    4) modify(a);
     System.out.println(a[0]);
     }
     public static void modify(int[] a){
    9) a[0]++;}
      }
    what is the result?
    A.The program runs and prints "0";
    B.The program runs and prints "1";
    C.The program runs but aborts with an exception;
    D.An error "possible undefined variable" at line 4 cause compilation to fail;
    E.An error "possible undefined variable" at line 9 cause compilation to fail;
Answer:B

 

 

SCJP认证复习——经典题库  我把147和104的题综合了一下,从个人的观点做了一些解析。也把其中的一些错误纠正了一些,多数题都通过了上机实测。但个人能力有限,对答案的正确性仍然不敢保证全都正确,所以请各位自行处理。  1. Given:1. public class returnIt {2. returnType methodA(byte x, double y){3. return (sh 阅读详情

相关推荐

《软件测试和质量管理》实验报告1——白盒测试

一、目的和要求 (1)掌握白盒测试技术,并能应用白盒测试技术设计测试用例 (2)能用Junit实施测试 二、实验内容 int DoWork(int x,int y,int z){ 1 int k=0,j=0; 2 if(( x>3 ) && ( z<10 )) 3 { 4 k=x*y-1; 5 j=sqrt(k); 6 } 7 if(( x= =4 ) || ( y>5 )) 8 j=x*y+10;

david2000999的博客 1万+

Java系列(三)__Java面向对象(1)

1、方法的定义及使用         方法是一段可以被重复调用的代码块,利用方法可以对一些重复使用的功能进行包装,并且统一维护。但是在Java之中对于方法有一些关键性的问题今天还不能够解决,所以今天给出的方法只是一个基础模式,而且只能够在主类中定义,由主方法直接调用。而这样方法的定义结构如下: public static 返回值类型 方法名称([数据类型 参数名称 , ..

鲍礼彬的优快云博客 ~_~ 1392

保姆级教程:用Protege 5.5.0从零构建你的第一个知识图谱(附实战案例文件)

本文提供了一份详细的Protege 5.5.0使用指南,从零开始构建知识图谱。涵盖环境配置、本体结构设计、实例填充到可视化展示的全流程,特别适合初学者快速掌握知识建模技术。通过实战案例演示,帮助读者理解如何定义类、属性及建立实例关系,是学习知识图谱构建的实用教程。

weixin_42548816的博客 555

白盒测试之逻辑覆盖(个人见解)

逻辑覆盖 逻辑覆盖是白盒测试中以程序内部的逻辑结构为基础的设计测试用例的技术。因为不可能进行穷尽的测试,有选择的执行程序中某些最具代表性的通路是对穷举测试唯一可行的代替方法。 语句覆盖:每个语句至少执行一次 判定覆盖:每个判定的每个分支至少执行一次 条件覆盖:每个判定的每个条件应取到各种相同的值 条件判定覆盖:同时满足判定覆盖与条件覆盖。 条件组合覆盖:每个判定中各条件的每一种组合至少出现出一次。 路径覆盖:程序中每一条可能的路径至少执行一次。 例如 public static int Test(i

weixin_43898816的博客 2088

ESP-IDF 利用ESP32构建智能音乐播放器(一)---------- 实现SD卡MP3文件的解码与播放

本文详细介绍了如何利用ESP32和ESP-IDF开发框架,从零开始构建一个智能音乐播放器。文章重点讲解了如何通过SD卡模块读取MP3文件,并集成Helix MP3解码库进行软件解码,最终通过I2S接口驱动音频模块实现播放。内容涵盖硬件连接、软件环境搭建、核心解码与输出逻辑,为嵌入式音频开发提供了完整的实战指南。

weixin_29163797的博客 234

SIwave仿真手册——电源完整性仿真之PDN阻抗的提取(四)

(想不到我这个弱鸡的博主有一天也有被催更的时候,看到后台被催的消息,我慌了,赶紧写一篇把。) 文章目录3.1 PDN阻抗的提取3.1.1手动完成PDN阻抗的提取1、创建pin group2、创建端口3、数据文件的清理和检查(参考1.3.4&1.3.5)4、添加电容模型(参考2.2.1)(==这一步很重要==)5、开始仿真6、查看仿真结果3.1.2利用向导工具完成PDN阻抗的提取1、点击图标![在这里插入图片描述](https://img-blog.csdnimg.cn/36d974339ea5449

luohuo9844的博客 1万+

Java 经典试题 (一)

Simulated Test of SCJP for JAVA2 PlatFORM (only for training) 1.  1)  public class ReturnIt{  2)  returnType methodA(byte x, double y){  3)  return (short)x/y*2;  4)  }  5)  }  what is valid returnT

幽客独往 5107

Spring Authorization Server自定义密码模式:突破标准OAuth2限制,实现MFA与复杂业务集成

OAuth 2.0授权框架是构建现代应用安全体系的基石,其密码模式(Resource Owner Password Credentials Grant)提供了一种直接的资源所有者凭证交换令牌的机制。该模式的核心原理是客户端收集用户密码并直接向授权服务器请求访问令牌,适用于受信任的客户端场景。在技术价值上,它简化了某些传统应用的OAuth集成流程。然而,标准实现往往难以满足复杂的现实业务需求,例如需要集成多因素认证(MFA)、对接外部LDAP目录服务或执行自定义密码加密校验等场景。Spring Authori

weixin_34302561的博客 438

二、C语言算法题期末题

1、用1元5角人民币兑换5分、2分、1分的硬币(每种都要有)共100枚,有多少种方案,每种方案的具体情况?

qq_43751506的博客 1030

Oracle EBS R12.2 安装 -- Step by Step

Oracle EBS R12.2 安装 -- Step by Step

Albert Tan DBA之路 1514

低成本实现webhook接收端[python]

Webook本质上也是API,只不过是反向调用,即前端不主动发送请求,完全由后端推送。简单来说,Webhook是一个接受HTTP POST或是GET,PUT,DELETE的URL,一个实现了Webhook的API提供商就是在当事件发生的时候会向配置的URL发送信息,与请求-响应式不同,使用Webhook可以实时接收到变化。Ps:Webhook可能会发出大量的请求,确保接受的URL不被泄露或者应用能及时处理这些请求。

锡城小凯的博客 1万+

2004年6月 SCJP考试回顾

上个月参加了SCJP考试,成绩是71的,本来这种分数是没有资格谈考试经历的。但如果你也和我一样,只是在实际的应用java,并且期望获得一个认证,下面的信息或许有些参考价值。 费用SCJP认证今年是6折 750RMB,应该还是比较优惠的,除了热考,认证是很少有优惠的。http://www.sesfocus.com/promotion/cn/sun_1470_o/email.html 考试时间我准备了

糖糖 的专栏 1167

保姆级教程:在爱快iKuai虚拟机里装OpenWrt旁路由,实现去广告和特殊功能

本文提供在爱快iKuai虚拟机中安装OpenWrt旁路由的详细教程,帮助用户实现去广告和特殊功能扩展。通过分步指导,包括虚拟机配置、网络设置和功能优化,打造稳定高效的家庭网络环境,特别适合软路由爱好者和网络管理员。

weixin_31364787的博客 835

SCJP专项

http://java.sun.com/docs/books/tutorial/books/3e/toc.html 说明:The Java Tutorial: Third Edition s Answers to Questions and Exercises online http://www.jchq.net/mockexams/exam1.htmhttp://www.jchq.ne

1193

TASK02【datawhale组队学习】视觉感知与手眼协调,计算机视觉在机器人中应用,手眼标定算法实现,深度估计与3D重建

参考教程AI硬件与机器人技术教程:https://github.com/datawhalechina/ai-hardware-robotics视觉感知与手眼协调,计算机视觉在机器人中应用,手眼标定算法实现,深度估计与3D重建单目深度估计 (Monocular Depth Estimation)DPT 的全称是 Dense Prediction Transformer。

m0_52024881的博客 1191

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

SCJP刷题学习笔记(Part eleven)

QUESTION 101 Given the code fragment: What is the result? A. A compilation error occurs at line n1. B. courseJava C. Javacourse D. A compilation error occurs at line n2. Correct Answer...

GOGOGO! 741

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Java开发教程(2)

karl,求教! 今天通过SCJP1.4 88% 爽!谢谢大家! 听说sun的sl275出了中文认证 请帮我分析147第106题 陷阱 请帮我分析题库104中第9题 147中53题为什么选C不是D吗?(版主帮我看一下) 通过scjp 考SCJP英文的是不是没有中英切换呀??? scjp考试难吗?要学什么内容?? scjp 1.4大...

weixin_33800593的博客 243

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

java是学习方程!

过了SCJP,得分94%,自我感觉良好。下面把我自己的复习,考试过程在这里做个小结吧:      1.知识背景和概况:      我不是程序员,在大学做毕业设计的时候用Java系统,后来就没有再用过Java了,2001年的时候上过SCJP培训,讲得太快,那个钱算是浪费了。后来由于种种原因一直没考,今年终于下定决心把这个心愿了结了。到目前为止,我的水平只能算是业余的,但是我有信心很快就成能

u012661800的专栏 895

程序员书单

作者:祁达方 链接:https://www.zhihu.com/question/47987341/answer/127576174 来源:知乎 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 java基础书籍:《scjp考试指南》无数次被人求推荐书籍,无数次说出这本书之后被鄙视:“我不是为了考证”。但这本书真不是只能用来考证。对j2se的讲解,既简约又精当,知识足够

tiantangpw的专栏 410

2021秋招学习笔记

文章目录Java基础篇学习(7/3-7/4)数据类型泛型、反射、注解、序列化(加实例)1、reflect类方法2、泛型3、反射原理这里补充java四大引用类型:**反射获取方法总结**反射使用方法invoke4、注解原理这里顺便提一句Java动态代理机制:5、序列化原理6、Clone的原理?7、BigInteger高精度数据结构+java+操作系统+网络(查漏补缺的)1、完全二叉树定义2、Inode元信息java序列化原理插入排序udp到达tcp功能拥塞控制-发送窗口大小问题7、Linux的inode8、线

Rookie1012的博客 3776

java第三次学习

java第三次学习 算术运算符 重点关注除 class OperatorDemo { public static void main(String[] args) { //定义变量 int x = 3; //把3赋值给int类型的变量x int y = 4; System.out.println(x+y); System.out.println(x-y); System.out.println(x*y); System.out.println(x/y); //整数相除

ZzZkiyou的博客 238

SCJP考试题-2

日志 > 软件编程 转载到我空间 复制本文网址 显示签名档 大字体 选用该信纸上一篇|下一篇|返回日志列表设置置顶 | 编辑 | 删除SCJP考试题-2发表于:2008年4月30日 13时53分46秒阅读(4)评论(0)本文链接:http://user.qzone.qq.com/169188811/blog/1209534826

yuzhu2008的专栏 1135

java Object数组

Object数组(可以存储不同类型数据) Object[] a= {1001,“ad”,12,“qwd”}; Object[][] aa=new Object[3][]; 并且能使用Arrays.toString()等方法进行数组工具操作

m0_67391377的博客 2317

软件测试实验1——语句覆盖、判定覆盖、条件覆盖、路径覆盖的用例设计及Junit测试

一、流程图 根据需求画出流程图 1、两个判定 MMM NNN 2、两个条件 M=(x>3)&&(z<10))M={(x>3) \&\& (z<10))}M=(x>3)&&(z<10)) N=(x==4)∣∣(y>5)N={(x==4)||(y>5)}N=(x==4)∣∣(y>5) 3、四条路径...

Jimmy Huang's Blog 2万+

JAVA 中 labeled break 语句

public class Demo {  public static void main(String [] args){  int i = 0,j = 5; tp:for(;;){  i ++; cc:for(;;){ if(i&gt; j--)break tp; } }  的System.out.println( “I =” + I + “J =” + j)的; }  } 结果:I = ...

博客 692

Object.create()、new Object()和{}的区别

平时代码中必定会使用对象,通常是用最直接的字面量方法创建var obj = {},最近在整理JS继承方式时遇到Object.create()也可以创建对象,另外,也可以用new Object()关键字创建。 那这三种方式有差别吗? 直接字面量创建 var objA = {}; objA.name = 'a'; objA.sayName = function() { console.log(`My name is ${this.name} !`); } // var objA = { // ..

hmily43的博客 1028
上一篇: 给大家嫖来一段截屏的代码(java原码)
下一篇: SCJP考试之套题2(SCJP_147)
SunnyJavaMoon
博客等级 码龄21年 20粉丝 36原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值