Scjp Exam 2

SCJP考题9

分类: SCJP考题 2007-10-13 15:22 267人阅读 评论(0) 收藏 举报
564. What will appear in the standard output when you run the Tester class?
class Tester{
int var;
Tester(double var){
This.var=(int)var;
}
Tester(int var){
this ("hello");
}
Tester(String s){
this();
System.out.println(s);
}
Tester(){
System.out.println("good-bye");
}
public static void main(String[]args){
Tester t=new Tester(5);
}
}
Select all valid answers.
A. nothing
B. "hello"
C. 5
D. "hello"followed by "good-bye"
E. "good-bye"followed by "hello"
正确答案:E

565. Imagine there are two exception classes called Exception1 and Exception2 that descend from the Exception class, Given these two class definitions:
class First{
void test() throws Exceotuib1, Exceotuib2{ …}
}
class Second extends First{
void test(){…}
Create a class called Third that extends Second and defines a test() method. What exceptions can Third's test() method throw?
Select all valid answers.
A. Exception 1
B. Exception 2
C. no checked exceptions
D. any exceptions declared in the throws clause of the Third's test()method.
正确答案:C

566. Which methods are correct overloading methods of the following method:
public void example(){…}
A. public void example(int m){…}
B. public int example(){…}
C. public void example2(){…}
D. public int example(int m,float f){…}
正确答案:A、D

567. Given the following fragment of code:
public class Base{
int w,x,y,z;
public Base(int a,int b){
x=a;
y=b;
}
public Base(int a,int b,int c,int d){
//assignment x=a,y=b
w=d;
z=c;
}
}
Which expressions can be used at the point of //assignment x=a,y=b?
A. Base(a,b);
B. x=a,y=b;
C. x=a,y=b;
D. this(a,b);
正确答案:C、D

568. The following code will give:
1: class Test{
2: static void show()
3: {
4: System.out.println("Static method in Test");
5: }
6: }
7: public class Q4 extends Test{
8: void show()
9: {
10:System.out.println("Overridden static method in Q4");
11:}
12:public static void main(String[]args)
13:{
14:}
15:}
Select all valid answers.
A. Compilation error at line 3.
B. Compilation error at line 10.
C. No compilation error, but runtime exception at line 3.
D. No compilation error, but runtime exception at line 10.
正确答案:B

569. Given the following code:
1) class Example{
2) String str;
3) public Example(){
4) str="example";
5) }
6) public Example(String s){
7) str=s;
8) }
9) }
10)class Demo extends Example{
11)}
12)public class Test{
13)public void f(){
14)Example ex = new Example("Good");
15)Demo d=new Demo("Good");
16)}
Which line will cause an error?
A. line 3
B. line 6
C. line 10
D. line 14
E. line 15
正确答案:E

570. Given the following class definition in one source file:
class Base{
public Base(){…}
public Base(int m){
…}
public void fun(int n){…}
}
public class Child extends Base{
member methods
}
Which methods can be added into the Child class correctly?
A. private void fun(int n){…}
B. viod fun(int n){
…}
C. protected void fun(int n){…}
D. public void fun(int n){
…}
E. public m(){//…}
正确答案:C、D

571. Which statements are correct?
A. In Java single inheritance is allowed, which makes code more reliable
B. A subclass inherits all methods(including he constructor)from the superclass
C. A class can implement as many interfaces as needed
D. When a class implements an interface, it can define as many methods of the interface as necded
正确答案:A、C

572. in the Test.Java source file, which are correct class definitions?
A. public class test{
public int x=0;
public test(int x)
{
this.x=x;
}
}
B. public class Test{
public int x=0;
public Test(int x){
this.x=x;
}
}
C. public class Test extends T1,T2{
public int x=0;
public Test(int x){
this.x=x;
}
}
D. public class Test extends T1{
public int x=0;
public Test(int x){
this.x=x;
}
}
E. protected class Test extends T2{
public int x=0;
public test(int x){
this.x=x;
}
}
正确答案:B、D

573. Given the following class definition:
class A{
protected int i;
A(int i){
rhia.i=i;
}
}
Which of the following would be a valid inner class for this class?
Select all valid answers.
A. class B{}
B. class B extends A{}
C. class B extends A{B(){System.out.println("i="+i);}}
D. class B{class A{}}
E. class A{}
正确答案:A

574. The following code is entire contents of a file called Example.java, causes precisely one error during compilation:
1) class SubClass extends BaseClass{
2) }
3) class BaseClass (){
4) String str;
5) public BaseClass(){
6) System.out.println("ok");}
7) public BaseClass(String s){
8) str=s;}}
9) public class Example{
10)Public void method(){
11)subClass s=new SubClass("hello");
12)BaseClass b=new BaseClass("world");
13)}
14)}
Which line would be cause the error?
A. 9
B. 10
C. 11
D. 12
正确答案:C

575. The piece of preliminary analysis work describes a class that will be used frequently in many unrelated parts of a project. "The polygon object is a drawable .A polygon has vertex information stored in a vector, a color, length and width."
Which Data type would be used?
A. Vector
B. int
C. String
D. Color
E. Date
正确答案:A、B、D

576. "The Employee object is a person, An Employee has appointment store in a vector, a hire date and a number of dependent "short answer: use shortest statement declare a class of Employee.
Fill in the blank.
正确答案:public class Employee extends Person

577. Give the following class definition in separate source files:
public class Example{
public Example(){
do something}
protected Example(int i){
do something}
protected void method(){
do something}
}
public class Hello extends Example{
member method and member variable
}
Which methods are corrected added to the class Hello?
A. public void Example(){}
B. public void method(){}
C. protected void method(){}
D. private void method(){}
正确答案:A、B、C

578. What happens when you try to compile and run the following program?
class Mystery{
String s;
public static void main(String[] args){
Mystery m=new Mystery();
m.go();
}
void Mystery(){
s="constructor";
}
void go(){
System.out.println(s);
}
}
Select the one right answer.
A. this code will not compile
B. this code compiles but throws an exception at runtime
C. this code runs but nothing appears in the standard output
D. this code runs and "constructor" in the standard output
E. this code runs and writes "null" in the standard output
正确答案:E

579. Given this skeleton of a class currently under construction:
public class Example{
int x,y,z;
public Example (int a,int b){
lots of complex computation
x=a; y=b;
}
public Example(int a,int b,int c){
do everything the same as single argument
version of constructor
including assignment x=a,y=b,z=c
z=c;
}
}
What is the most concise way to code the "do everything…"part of the constructor taking two arguments?
Fill in the blank.
正确答案:this(a,b);

580. Which are correct class declarations? Assume in each case that the text constitutes the entire contents of a file called Fred java?
A. public class Fred{
public int x=0;
public Fred(int x){
this.x=x;
}
}
B. public class fred{
public int x=0;
public Fred(int x){
this x=x;
}
}
C. public class Fred extends
MyBaseClass, MyOtherBaseClass{
public int x=0;
public Fred(int xval){
x=xval;
}
}
D. public class Fred{
private int x=0;
private Fred(int xval){
x=xval;
}
}
E. import java awt.*;
public class Fred extends Object{
int x;
private Fred(int xval){
x=xval
}
}
正确答案:A、E

581. Look the inheritance relation:
In a source of java have the following line:
woman w=new man();
what statement are corrected?
A. The expression is illegal.
B. Compile corrected but running wrong.
C. The expression is legal.
D. Will construct a woman's object.
正确答案:A

582. The following is a program.
1) class Exsuper{
2) String name;
3) String nick_name;
4)
5) public Exsuper(String s.String t){
6) name = s;
7) nick_name = t;
8) }
9)
10)public String toString(){
11)return name;
12)}
13)}
14)
15)public class Example extends ExSuper{
16)
17)public Example(String s.String t){
18)super(s,t);
19)}
20)
21)Public String toString(){
22)return name +"a.k.a"+nick_name;
23)}
24)
25)public static void main(String args[]){
26)Exsuper a=new Example("First","1st")
27)Exsuper b=new Example("Second","2nd")
28)
29)System.out.println("a is"+a.toString());
30)System.out.println("b is"+b.toString());
31)}
32)}
What happens when the user attempts to compile and run this program?
A. A Compiler error occurs at line 21
B. An object of type ClassCastException is thrown at line 27
C. The following output:
a is First
b is second
D. The following output:
a is First
b is Secong a.k.a 2nd
E. The following output:
a is First a.k.a 1st
b is Second a.k.a 2nd
正确答案:D

583. Which statement is true about an inner class?
A. It must be anonymous
B. It can not implement an interface
C. It is only accessible in the enclosing class
D. It can access any final variables in any enclosing scope.
正确答案:D

584. Which best describes the requirements of a fully encapsulated class?
A. Methods must not be private.
B. Variables must not be public.
C. The class must be marked final
D. Public methods are all marked final.
E. Modification of the objects state is only possible using method calls.
正确答案:E

585. Given the following class definition:
class A{
public int x;
private int y;
class B{
protected void method(){
}
class C{
private void method2(){
}
}
}
}
class D extends A{
public float z;
}
What can method2() access directly, without a reference to another to another instance?
Select all valid answers.
A. the variable x defined in A
B. the variable y defined in A
C. method1 defined in B
D. the variable z defined in D
正确答案:A、B、C

586. Given this interface definition:
interface A{
int method1(int i);
int method2(int j);
}
Which of the following classes implements this interface and is not abstract?
A. clasas B implements A{
int method1(){…}
int method2(){…}
}
B.class B{
int method1(int i){…}
int method2(int j){…}
}
C. class B implements A{
int method1(int i){…}
int method2(int j){…}
}
D. class B extends A{
int method1(int i){…}
int method2(int j){…}
}

E. class B implements A{
int method1(int i){…}
int method2(int j){…}
}
正确答案:C、E

587. Write a statement for a constructor that invokes the no-args, default constructor in its super class.
Fill in the blank
正确答案:super();

588. What happens when you try to compile and run the following program?
class Mystery{
String s;
public static void main(String[]args){
Mystery m=new Mystery();
m.go();
}
void Mystery(){
s="constructor";
}
void go(){
System.out.println(s);
}
}
Select the one right answer.
A. this code will not compile
B. this code compiles but throws an exception at runtime
C. this code runs but nothing appears in the standard output
D. this code runs but "constructor" in the standard output
E. this code runs and writes "null" in the standard output
正确答案:E

589. Why won't the following class compile?
class A{
private int x;
public static void main(String[] args){
new B();
}
class B{
B(){
System.out.println(x);
}
}
}
Select the one right answer.
A. Class B tries to access a private variable defined in its outer class
B. Class A attempts to create an instance of B when there is no current instance of class A.
C. Class B's constructor must be public.
正确答案:B

590. What will happen if you try to compile and execute B's main() method?
class A{
int i;
A(int i){
this i=i*2;
}
}
class B extends A{
public static void main(String[] args){
B b = new B(2);
}
B(int i){
System.out.println(i);
}
}
Select the one right answer.
A. The instance variable i is set to 4
B. The instance variable i is set to 2
C. The instance variable i is set to 0
D. This code will not compile
正确答案:D

591. Which of the following statements are true?
A. Methods cannot be overridden to be more private
B. Static methods cannot be overloaded
C. Private methods cannot be overloaded
D. An overloaded method cannot throw exceptions not checked in the base class
正确答案:A

592. What will happen if you attempt to compile and run the following code?
class Base {}
class Sub extends Base {}
class Sub2 extends Base {
public class CEx{
public static void main(String argv[]){
Base b=new Base();
Sub s=(Sub)b;
}
}
Select the one right answer.
A. Compile and run without error
B. Compile time Exception
C. Runtime Exception
正确答案:C

593. Which of the following methods can be legally inserted in place of the comment?
class Base{
public void amethod(int i){ }
}
public class Scope extends Basc{
public static void main(String argv[]){
}
//Method Here
}
Select the one right answer.
A. void amethod(int i) throws Exception {}
B. void amethod(long i) throws Exception {}
C. void amethod(long i){}
D. public void amethod(int i) throws Exception {}
正确答案:B、C

594. Gives the following code:
public class MyClass1{
public static void main(String argv[]){ }
/*Modifier at XX*/class MyInner {}
}
What modifiers would be legal at XX in the above code?
A. public
B. private
C. static
D. friend
正确答案:A、B、c

595. Given the following code how could you invoke the Base constructor that will print out the string "base constructor";
class Base{
System.out.println("base constructor");
}
Base(){
}
}
public class Sup extends Base{
public static void main(String argv[]){
Sup s=new Sup();
One
}
Sup(){
Two
}
public void derived(){
//Three
}
}
Select the right answer.
A. On the line After //One put Base(10);
B. On the line After //One put super(10);
C. On the line After //Two put super(10);
D. On the line After //Three put super(10);
正确答案:C

596. What will happen when you attempt to compile and run the following code?
class Base{
private void amethod(int iBase){
System.out.println("Base.amethod");
}
}
class Over extends Base{
public static void main(String argv[]){
Over o=new Over();
int iBase=0;
o.amethod(Base);
}
public void amethod(int iOver){
System.out.println("Over.amethod");
}
}
Select the right answer.
A. Compile time error complaining that Base.amethod is private
B. Runtime error complaining that Base.amethod is private
C. Output of "Base.amethod"
D. Output of "Over.amethod"
正确答案:D

597. For a class defined inside a method, what rule governs access to the variables of the enclosing method?
A. The class can access any variable
B. The class can only access static variables
C. The class can only access transient variables
D. The class can only access final variables
正确答案:D

598. What will happen when you attempt to compile and run the following code?
import java.io.*;
class Base{
public static void amethod()
throws FileNotFoundException{}
}
public class ExcepDemo extends Base{
public static void main(String argv[]){
ExcepDemo e=new ExcepDemo();
}
public static void amethod(){}
protected ExcepDemo(){
try{
DataInputStream din=
new DataInputStream(System,in);
System.out.println("Pausing");
din readChar();
System.out.println("Continuing");
This.amethod();
}catch(IOException ioe){}
}
}
Select the one right answer.
A. Compile time error caused by protected constructor
B. Compile time error caused by amethod not declaring Exception
C. Runtime error caused by amethod not declaring Exception
D. Compile and run with output of "Pausing" and" Continuing" after a key is hit
正确答案:D

599. What will happen when you attempt to compile and run this program?
public class Outer{
public String name="Outer";
public static void main(String argv[]){
Inner i=new Inner();
i.showName();
}
End of main
private class Inner{
String name=new String("Inner");
void showName(){
System.out.println(name);
}
}
End of Inner class
}
Select the one right answer.
A. Compile and run with output of "Outer"
B. Compile and run with output of "Inner"
C. Compile time error because Inner is declared as private
D. Compile time error because of the line creating the instance of lnner
正确答案:D

600. Your chief Software designer has shown you a sketch of the new Computer parts system she is about to create. At the top of the hierarchy is a Class called Computer and under this are two child classes. One is called LinuxPC and one is called WindowsPC.
The main difference between the two is that one runs the Linux operating System and the other runs the Windows System(of course another difference is that one needs constant re-booting and the other runs reliably),Under the WindowsPC are twp Sub classes one called Server and one Called Workstation. How might you appraise your designers work?
A. Give the go-ahead for further design using the current scheme
B. Ask for a re-design of the hierarchy with changing the Operating System to a field rather than Class type
C. Ask for the option of WindowsPC to be removed as it will soon be obsolete
D. Change the hierarchy to remove the need for the superfluous Computer Class
正确答案:B

601. Which of the following statements are true?
A. An inner class may be defined as static
B. There are No circumstances where an inner class may be defined as private
C. An anonymous class may have only one constructor
D. An inner class may extend another class
正确答案:A、D

602. Given the following class definition, which of the following methods could be legally placed after the comment?
public class Rid{
public void amethod(int j,String s){}
//Here
}
Select the one right answer.
A. public void amethod(String s,int i){}
B. public int amethod(int i,String s){}
C. public void amethod(int i,String mystring s){}
D. public void Amethod(int i,String s){}
正确答案: A、D

603. Given the following class definition which of the following can be legally placed after the comment line?
class Base{
public Base(int i){}
}
public class MyOver extends Base{
public static void main(String arg[]){
MyOver m=new MyOver(10);
}
MyOver(int i){
super(i);
}
MyOver(String s,int i){
this(i);
//Here
}
}
Select the one right answer.
A. MyOver m=new MyOver();
B. super();
C. this("Hello",10);
D. Base b=new Base(10);
正确答案: D

604. Given the following class definition which of the following statements would be legal after the comment?
class InOut{
String s=new String("Between");
public void amethod(final int iArgs){
int iam;
class Bicycle{
public void sayHello(){
Here
}
End of bicycle class
}
}//End of amethod
public void another(){
int iOther;
}
}
Selec the one right answer.
A. System.out.println(s);
B. System.out.println(Other);
C. System.out.println(iam);
D. System.out.println(Args);
正确答案: A、D

605. Which of the following statements are true?
A. An interface can only contain method and not variables
B. Interfaces cannot have constructors
C. A class may extend only one other class and implement only one interface
D. Interfaces are the Java approach to addressing its lack of multiple inheritance, but require implementing classes the functionality of the Interfaces
正确答案: B、D

606. What will happen when you attempt to compile and run the following code?
class Base{
public void Base(){
System.out.println("Base");
}
}
public class In extends Base{
public static void main(String argv[]){
In i=new In();
}
}
Select the one right answer.
A. Compile time error Base is a keyword
B. Compile and no output at runtime
C. Output of Base
D. Runtime error Base has no valid constructor
正确答案: B

607. Which of the following statements are true?
A. Constructors cannot have a visibility modifier
B. Constructors can be marked public and protected, but not private
C. Constructors can only have a primitive return type
D. Constructors are not inherited
正确答案: D

608. What will happen when you attempt to compile and run the following code?
class Base{
Base(int i){
System.out.println("Base");
}
}
class Severn extends Base{
public static void main(String argv[]){
Severn s=new Severn();
}
void Severn(){
System.out.printl("Severn");
}
}
Select the one right answer.
A. Compilation and output of the string "Severn" at runtime
B. Compile time error
C. Compilation and no output at runtime
D. Compilation and output of the string "Base"
正确答案: B

609. Which of the following statements are true?
A. The default constructor has a return type of void
B. The default constructor takes a parameters of void
C. The default constructor takes no parameters
D. The default constructor is not created if the class has any constructors of its own
正确答案: C、D

610. Which of the following statements statement are true?
A. All of the variables in an interface are implicitly static
B. All of the variables in an interface are implicitly final
C. All of the methods in an interface are implicitly abstract
D. A method in an interface can access class level variables
正确答案: A、B、C

SCJP考题10

分类: SCJP考题 2007-10-13 15:25 239人阅读 评论(0) 收藏 举报
10.What output is produced by the following program?
class Test{
public static void main(String args[]){
long size=10;
int[] array=new int[size];
size=20;
System.out.println(array.length);
}
}
Select the one right answer.
A. A compiler error.
B. A runtime error.
C. 10
D. 20
正确答案:A

11. What output is produced by the following program"
class Test{
public static void main(String args[]){
char size=10;
int[] array=new int[size];
size=20;
System.out.printiln(array.length);
}
}
Select the one right answer.
A. A comoiler error.
B. A runtime error.
C. 10
D. 20
正确答案:C

12. True or false? Elemint values in Java arrays are automatically initialized when the arrays is constructed using the new operator.
Fill in the blank.
正确答案:Thue

13. When an array of char elements is constructed, the elements are automatically initialized to which of the following values:
A. '0'
B. '/u0000'
正确答案:B

14. What output is produced by the following program?
class Test{
public static void nain(String args[]){
char[] a1={'u/0030','/u0031'};
System.out.println(a1[1]);
}
}
Select the one right answer.
A. A compiler error
B. A runtime error
C. 30
D. 31
E. 0
F. 1
正确答案: F

15. What output is produced by the following program? (Note the placeholder comma in the boldface portion.)
class Test{
public static void main(String args[1]){
char[] a1={'u/0030', , '/u0031'};
Sysem.out.println(a1[0]);
}
}
Select the one right answer.
A. A compiler error
B. A runtime error
C. 0
正确答案:A

16. What is the name of the property of an array object that always contains the size of the array and how may it be used?
Fill in the blank
正确答案:length

17. True or false? All Java applications and applets require a main() method.
Fill in the blank.
正确答案:False

18. Show six different ways to express the decimal value 28 as an integral literal.
Fill in the blank.
正确答案:28,034, 0x1c, 0x1C, 0X1c, 0X1C

19. True false? By default, an integral literal is a 64 bit value
Fill in the blank.
正确答案:False

240. What output is produced by the following program?
class Test{
public static void main(String args[]){
try{
int x=64;
int y=0;
System.out.println(x%y);
}catch(Exception e){
System.out.println("Exception");
}
}
}
Select all of the right answers from the flowing
A. A compiler error
B. Exception
C. Infinity
D. NaN
正确答案:B

241. What output is produced by the following program?
class Test{
public static void main(sString args[]){
System.out.println(Double.isNaN(3.0%0));
System.out.print("");
System.out.println(Double.isNaN(3.0/0));
}
}
Select of the right answers.
A. false false
B. false ture
C. ture false
D. true true
正确答案:C

242. What output is produced by the following program?
class Test{
public static void main(String args[]){
try{
double x=64.0;
double y=0.0;
System.out.println(x%y==x%y);
}cateh(Exception e){
System.out.println("Exception");
}
}
}
Select all of the right answers from the flowing
A. A compiler error
B. Exception
C. true
D. fatse
正确答案:D

243. What output is produced by the following program?
class Test{
public static void main(String args[]){
try{
System.out.println(Float.NaN==Float NaN);
System.out.println(""+
(Float.POSITIVE.INFINITY==Float.POSITIVE_INFINITY));
}catch(Exception e){
System.out.println("Exception");
}
}
}
Select all of the right answers
A. A compiler error
B. Exception
C. true true
D. fatse false
正确答案:D

244. What is the operator for the bit shift and rotate operation in Java?
Fill in the blank.
正确答案:There is no bit shift and rotate operator.

245. True or faise? Integer division by zero, including a modulo(%) operation results in an ArithmeticException. No other arithmetic operation in Java can throw an exception. Instead, all other arithmetic operations proceed to a result, even though that result might be arithmetically incorrect.
Fill is the blank.
正确答案:Ture

246. What output is produced by the following program?
class Test{
public static void main(String args[]){
try{
byte x=-32;
byte y=(byte)(x»2);
System.out.println(y);
}catch(Exception e){
System.out.println("Exception");
}
}
}
Select all of the right answers from the flowing.
A. A compiler error
B. Exception
C. -4
D. -8
E. -16
F. -32
G. None of the above
正确答案: D

247. What output is produced by the following program?
class Test{
public static void main(String args[]){
try{
int x=-7;
System.out.println(x/2+""+(x»1));
}catch(Exception e){
System.out.println("Exception");
}
}
}
Select all of the right answers from the flowing.
A. A compiler error
B. Exception
C. -3 -3
D. -3 -4
E. -4 -4
F. None of the above
正确答案: D

248. What output is produced by the following program?
class Test{
public static void main(String args[]){
try{
int x=16384;
System.out.println(x»33);
}catch(Exception e){
System.out.println("Exception");
}
}
}
Select all of the right answers.
A. A compiler error
B. Exception
C. 0
D. 1
F. None of the above
正确答案: F

249. What output is produced by the following program?
class Test{
public static void main(String args[]){
try{
byte x=127;
byte y=(byte)(x»9);
System.out.println(y);
}catch(Exception e){
System.out.println("Exception");
}
}
}
Select all of the right answers from the flowing.
A. A compiler error
B. Exception
C. 0
D. 1
E. -1
F. None of the above
正确答案: C

401. What will happen when you attempt to compile and run this code?
class Test{
public static void main(String argv[]){
}
public static native void amethod();
}
Select the one right answer.
A. Error at compilation: native method cannot be static
B. Error at compilation native method must return value
C. Compilation but error at run time unless you have made code containing native amethod available
D. Compilation and execution without error
正确答案: D

402. What will happen when you attempt to compile and run the following code?
public class Test{
public static void main(String argv[]){
Test h =new Test();
}
protected Test(){
for(int i=0;i<10;i++){
System.out.prinln(i);
}
}
}
Select the one right answer.
A. Compilation error: Constructors cannot be declared protected
B. Run time error: Constructors cannot be declared protected
C. Compilation and running with output 0 to 10
D. Compilation and running with output 0 to 9
正确答案: D

403. What will happen when you attempt to compile and run the following code with the command line "hello there"?
public class Test{
String[] MyArg:
public static void main(String argv[]){
MyArg=argv;
}
public void amethod(){
System.out.println(argv[1]);
}
}
Select the one right answer.
A. Compile time error
B. Compilation and output of "hello"
C. Compilation and output of "there
D. None of the above
正确答案: A

404. What will happen when you attempt to compile and run this code?
import java.awt event.*;
import java.awt.*;
public class Test extends Frame implements WindowListener{
public void WindowClosing(WindowEvent e){
System.exit(0);
}
public void Test(){
setSize(300,300);
setVisible(true);
}
}
Select the one right answer.
A. Error at compile time.
B. Visible Frame created that that can be closed.
C. Compilation but no output at run time.
D. Error at compile time because of comment before import statements.
正确答案: A

405. Which of the following statements are true?
A. If a class has any abstract methods it must be declared abstract itself.
B. All methods in an abstract class must be declared as abstract.
C. When applied to a class, the final modifier means it cannot be sub-classed.
D. transient and volatile are Java modefiers.
正确答案: A、C、D

406. Which of the following are valid methods?
A. publie static native void amethod(){}
B. public static void amethod(){}
C. private protected void amethod(){}
D. static native void amethod();
正确答案: B、D

407. Which of the following statements are true?
A. static methods do mot have access to the implicit variable called this.
B. A static method may be called without creating an instance of its class.
C. A static method may not be overridden to be non-static.
D. A static method may not be overloaded.
正确答案: A、B、C

408. Which of the following statements are true about a variable created with the static modifier?
A. Once assigned the value of a static variable may not be altered.
B. A static variable created in a method will keep the same value between calls.
C. Only one instance of a static variable will exist for any amount of class instances.
D. The static modifier can only be applied to a primitive value.
正确答案: C

409.What will happen when you attempt to compile and run the following code?
import jana.io.*;
class Test{
abstract public void martley(){
}
}
public class MyEx extends Test{
public static noid main(String argv[]){
DatalnputStream fi=new DatalnputStream(Stream.in);
try{
fi.readChar();
}eatch(IOException e){
System.exit(0);
}
finally{
System.out.println("Dokng finally");}
}
}
}
Select the one right answer.
A. Compile time error.
B. It will run,wait for a key press and then exit.
C. It will run,wait for a keypress,print"Doing finally"then exit.
D. At run and immediately exit.
正确答案: A

410. Given the following code:
class Test {
static int oak=99;
}
public class Doverdate extends Test{
public static void main(String argv[]){
Doverdale d=new Doverdale();
d.amethod();
}
public void amethod(){
Here
}
}
Which of the following if placed after the comment
Here, will compile and modify the value of the variable oak?
A. super.oad=1;
B. oak=33;
C. Test.oak=22;
D. oak=50.1;
Select the one right answer.
A. Error at compile time.
B. Visible Frame created that that can be closed.
C. Compilation but no output at run time.
D. Error at compile time because of comment before import statements.
正确答案: A、B、C

476. Which of the following statements are legal?
A. long 1=4990;
B. int i=4L;
C. float f=1.1;
D. double d=34.4;
E. double t=0.9F
正确答案: A、D、E

477. The variable "result" is boolean. Which expressions are legal?
A. result=true;
B. if(result){do something…}
C. if(result!=0){
so something…}
D. result=1
正确答案: A、B

478. Class Teacher and Student are subclass of class Person.
Person p;
Teacher t;
Student s;
p,t and s are all non-null.
if(t instanceof Person){s=(Student)t;}
What is the result of this sentence?
A. It will construct a Student object.
B. The expression is legal.
C. It is illegal at compilation.
D. It is legal at compilation but possible illegal at runtime.
正确答案: C

479. What will happen if you compile/run the following code?
1: class Test
2: {
3: static void show()
4: {
5: System.out.println("Show method in Test class");
6: }
7: }
8:
9: public class Q2 extends Test
10:{
11:static void show()
12:{
13:System.out.println("Show method in Q2 class");
14:}
15:public static void main(String[]args)
16:{
17:Test t=new Test();
18:t.show();
19:Q2 q=new Q2();
20:q.show();
21:
22:t=q;
23:t.show();
24:
25:q=t;
26:q.show();
27:}
28:}
A. prints "Show method in Test class"
"Show method in Q2 class"
"Show method in Q2 class"
"Show method in Q2 class"
B. prints "Show method in Test class"
"Show method in Q2 class"
"Show method in Test class"
"Show method in Test class"
C. prints "Show method in Test class"
"Show method in Q2 class"
"Show method in Test class"
"Show method in Q2 class"
D. Compilation error.
正确答案: D

480. What will happen when you invoke the following method?
1: void infiniteLoop()
2: {
3: byte b=1;
4:
5: while(++b>0);
6: System.out.println("Welcome to Java");
7: }
Select the one right answer.
A. The loop never ends(infiniteLoop).
B. Prints "Welcome to Java".
C. Compilation error at line 5. ++ operator should not be used for byte type variables.
D. Prints nothing.
正确答案: B

481. What is the output for the following lines of code?
1: System.out.println(" "+2+3);
2: System.out.println(2+3);
3: System.out.println(2+3+" ");
4: System.out.println(2+" "+3);
Select the one right answer.
A. Compilation error at line 3
B. Prints 23,5,5 and 23.
C. Prints 5,5,5 and 23.
D. Prints 23,5,23 and 23.
正确答案: B

482. Consider the following class:
classTest(int i){
void test(int i){
System.out.println("I am an int.");
}
void test(String s){
System.out.println("I am an int.");
}
public static void main(String s[]){
Test t=new Test();
char ch='y';
t.test(ch);
}
}
Which of the statements below is true? (Choose one)
A. Line 5 will not compile, because void methods cannot be overridden.
B. Line 12 will not compile, because there is no version of test() that rakes a char argument.
C. The code will compile and will throw an exception at line 12.
D. The code will compile and produce the following output: I am an int.
E. The code will compile and produce the following output: I am a String.
正确答案: D

483. Which of the following do not lead to a runtime error?
Select all correct answers.
A. "john"+"was"+"here"
B. "john"+3
C. 3+5
D. 5+5.5
正确答案: A、B、C、D

484. What is the output when following code is run?
1. class OuterOne{
2. class InnerOne extends OuterOne{}
3. static void thisMethod(){
4. Object o=(Object)new OuterOne();
5. OuterOne foo=(OuterOne)o;
6. }
7. public static void main(String args[]){
8. thisMethod();
9. }
10.}
Select the one right answer.
A. Will compile fine, but at runtime a ClassCastException is thrown
B. Will compile and run fine
C. Compiler error at line 4
D. Compiler error at line 5
正确答案: B

485. Given the following code:
1. public static void main(String args[]){
2. byte b=12;
3. byte c=126;
4. byte d=b-c;
5. System.out.println(d);
6. }
Select the one right answer.
A. Compilation succeeds and prints 1.
B. Compilation succeeds but there will a Runtime Exception.
C. Compilation error at line no 4.
D. Compilation error at line no 5.
正确答案: C

486. Given the following code:
Class Test{
public static void main(String args[]){
float[][]f1=1.2f,2.3f},{4.5f,5.6f
Object oo=f1;
f1[1][1]=oo;
System.out.println("Best Wishes"+f1[1][1]);
}
}
What will the output?
A. {4.5,5.6}
B. 4.5
C. compilation error in line no.5
D. exception
正确答案: C

551. What is the value of j when printed?
class Test{
public static void main(String args[]){
long x=4, j=0;
switch(x){
case 1:j++;
case 2:j++;
case 3:j++;
case 4:j++;
case 5:j++;
break;
default:j++;
}
System.out.println(j);
}
}
Select the one right answer.
A. 1
B. Compiler error
C. 6
D. 3
E. 2
正确答案:B

552. Given the following code:
import java.io*;
class Test{
static void method() throws Exception{
throw new EOFException();
}
public static voidmain(String args[]){
try{
method();
}catch(){
}
}
}
Which of the following should be placed at so that the code will compile without errors?
A. IOExeption e
B. EOFExceotion e
C. MalformedURLException e
D. NullPointerException e
E. Exception e
F. FileNotFoundException
正确答案:E

553. Given the following code:
switch(s){
default: System.out.println("Best Wishes");
}
Which datatype can 's' be?
A. byte
B. long
C. float
D. double
正确答案:A

554. Given the following code:
public static void main(String args[]){
int i=1;
int j=10;
do{
if(i>j)
continue;
j—;
} while(++i<6);
System.out.println("i="+i+"j="+j);
}
What will be the output?
A. i=4,j=5
B. i=5,j=6
C. i=5,j=5
D. i=4,j=6
E. i=6,j=5
正确答案:E

555. What is the output?
class Test{
public static void main(String args[]){
default;
for(int i=0; i<10; i++){
mid:
for(int j=0;j<5;j++){
System.out.println(j);
}
}
}
}
Select the one right answer.
A. runtime exeption
B. print 0—4
C. compilation error
正确答案:C

556. Given the following code:
1. class Test{
2. public static void main(String args[]){
3. int x=4;
4. int y=2;
5. if(x/y){
6. System.out.println(x+y);
7. }
8. }
9. }
What is the output?
A. prints 6
B. compilation error at line no.6
C. compilation error at line no.5
D. runtime exception occurs
E. prints 4
正确答案:C

557. Given the following code:
switch(x){
case 1:System.out.println("case 1");
case 2:
case 3:System.out.println("case 2");}
break;
default:System.out.println("case 3");}
For what values of x will the output include case 3.
A. 1
B. 2
C. 3
D. 4
正确答案:D

558. Given the following code:
if(x>4){
System.out.println("case 1");
}
else
if(x>9){
System.out.println("case 2");
}
else
System.out.println("case 3");
}
What value(s)of x will cause case 3 printed in the output?
A. less than zero.
B. less than 4
C. between 4 and 9
D. 10 and greater
E. none
正确答案:B

559. Given the following code:
try{
method();
some code1
}
catch(IOException a){
some code2
}
finally{
some code3
}
some code4
What will be excecuted if the method throws NullPointerException?
A. some code2 run
B. some code3 run
C. some code3 and some code4
D. Compilation Error
正确答案:C

560. Given the following code:
1. //
2. if(method()){
3. //}
4. else{
5. //
6. }
7. //
Which line you insert the throw mew Exception if the code should throw the exception only if the method() returns true?
A. 2
B. 3
C. 4
D. 5
正确答案:B
671. Given the following code:
class Super{
int i=0
Super(String s){
i=10
}
}
class Sub extends Super{
Sub(String s){
i=20;
}
public static void main(String args[]){
Sub b=new Sub("hello");
System.out.printIn(i);
What will be the value of i?
A. Compilation Error
B. Runtime Error
C.0
D.10
E.20
正确答案:E

672. Where will be a 'is a' relationship will occur select one?

A. interface Person
class Employee implements Person
B. interface Shape
interface Rectangle extends Shape
C. interface Component
class Objects implement Component{
Component[] Component;
}
正确答案: B

673.which are the correct forms of Constructors for the class hai?
A. public void hai(int a)
B. hai(int a,int b)
C. public hai(int a)
D. int hai(int c, int d)
E. int hai()
F. int hai(String s)
正确答案: B C

674. Which are the orrect forms of overriding for the method void hai(int a,int b)?
A.public void hai(int a,int b)
B.protected void hai(int a,int b)
C.public hai(int a)
D.int hai(int c,int d)
E.int Hai()
f.int hai(String s)
正确答案: A B

675. Given the following code:
1.interface foo
2.{
3.int I=0;
4.}
5.class sreejith implements foo
6.{
7.public static void main(String args[])
8.{sreejith s=new sreejith();
9.int j=0;
10.j=s.I;
11.j=sreejith.I;
12.j=foo.i;
13.s.I=2;
}
}

where will compilation fail?

A.10
B.11
C.12
D.13
E. No error
正确答案:D

676.What is the modifier is used to make a method to be overridden in subclass?
A. final
B. abstract
C. static
D. volatile
正确答案:B

677. Giventhe following code:
public class Outer{

}
What should be inserted at /
// so that the code will compile fine?
A. private class Inner{
static int k;
}
B. static class Inner{
static int k;
}
C. public class Inner{
static int k;
}
D. public abstract class Inner{
public abstract void method();
}
正确答案:B D

678.Which of the following are true about encapsulation?
A. Direct access to variables.
B. Access to variables through methods.
C. keeping methods protected.
D. use methods access and modify the variable data.
正确答案:B D

679.Given the following code:
1.class Happy {
2.public static void main(String args[]){
3.public class Sad {
4.public void methodA() {
5.System.out.println("inside sad");
6.}
7.}
8.System.out.println("inside happy");
9.}
10.}
What will be the output?
A. compilation error at line no.3
B. compilation error at line no.4
C. compilation error at line no.5
D. compilation succeeds but runtime exception
E. clean compile and give the output "inside happy"
正确答案: A

680. What is true about constructors?
A. They initialize all the member variables
B. They initialize all the instance variables
C. If there is no constructor. the compiler includes default constructor.
D. Compiler supplied constructor will invoke the default constructor of the super class.
正确答案: C D

SCJP考题11

分类: SCJP考题 2007-10-13 15:30 407人阅读 评论(0) 收藏 举报
564. What will appear in the standard output when you run the Tester class?
class Tester{
int var;
Tester(int var){
this ("hello");
}
Tester(String s){
this();
System.out.println(s);
}
Tester(){
System.out.println("good-bye");
}
public static void main(String[]args){
Tester t=new Tester(5);
}
}
Select all valid answers.
A. nothing
B. "hello"
C. 5
D. "hello"followed by "good-bye"
E. "good-bye"followed by "hello"
正确答案:E

565. Imagine there are two exception classes called Exception 1 and Exception2 that descend from(从——下来) the Exception class,Given these two class definitions:
class First{
void test()throws Exceotuib1,Exceotuib2(…)
}
class Second extends First{
void test(){…}
Create a class called Third that extends Second and defines a test()method.What exceptions can Third's test() method throw?
Select all valid answers.
A. Exception 1
B. Exception 2
C. no checked exception 3
D. any exceptions declared in the throws clause of the Third's test()method.
正确答案:C

566. Which methods are correct overloading methods of the following method:
public void dxample(){…}
A. public void example(int m){…}
B. public int example(){…}
C. public void example2(){…}
D. public int example(int m,float f){…}
正确答案:A、D

567. Given the following fragment of code:
public class Base{
int w,x,y,z;
public Base(int a,int b){
x=a;
y=b;
}
public Base(int a,int b,int c,int d){
//assignment x=a,y=b
w=d;
z=c;
}
}
Which expressions can be used at the point of //assignment x=a,y=b?
A. Base(a,b);
B. x=a,y=b;
C. x=a;y=b;
D. this(a,b);
正确答案:C、D

568. The following code will give:
1: class Test{
2: static void show()
3: {
4: System.out.println("Static method in Test");
5: }
6: }
7: public class Q4 extends Test{
8: void show()
9: {
10:System.out.println("Overridden static method in Q4");
11:}
12:public static void main(String[]args)
13:{
14:}
15:}
Select all valid answers.
A. Compilation error at line 3.
B. Compilation error at line 10.
C. No compilation error,but runtime exception at line 3.
D. No compilation error,but runtime exception at line 10.
正确答案:B

569. Given the following code:
1) class Example{
2) String str;
3) public Example(){
4) str="example";
5) }
6) public Example(String s){
7) str=s;
8) }
9) }
10)class Demo extends Example{
11)}
12)public class Test{
13)public void f(){
14)Example ex = new Example("Good");
15)Demo d=new Demo("Good");
16)}
Which line will cause an error?
A. line 3
B. line 6
C. line 10
D. line 14
E. line 15
正确答案:E

570. Given the following class definition in one source file:
class Base{
public Base(){…}
public Base(int m){
…}
public void fun(int n){…}
}
public class Child extends Base{
member methods
}
Which methods can be added into the Child class correctly?
A. private void fun(int n){…} 范围变小
B. viod fun(int n){
…}
C. protected void fun(int n){…}
D. public void fun(int n){
…}
E. public m(){//…}
正确答案:C、D

571. Which statements are correct?
A. In Java single inhetance is allowed,which makes code more reliable
B. A subclass inherits all methods(including the constructor)from the superclass 私有的??
C. A class can implement as many interfaces as needed
D. When a class implements an interface,it can define as many methods of the interface as needed
正确答案:A、C

572. in the Test.Java source file,which are correct class definitions?
A. public class test{
public int x=0;
public test(int x)
{
this.x=x;
}
}
B. public class Test{
public int x=0;
public Test(int x){
this.x=x;
}
}
C. public class Test extends T1,T2{
public int x=0;
public Test(int x){
this.x=x;
}
}
D. public class Test extends T1{
public int x=0;
public Test(int x){
this.x=x;
}
}
E. protected class Test extends T2{
public int x=0;
public test(int x){
this.x=x;
}
}
正确答案:B、D

573. Given the following class definition:
class A{
protected int i;
A(int i){
this.i=i;
}
}
Which of the following sould be a valid inner class for this class?
Select all valid answers.
A. class B()
B. class B extends A{}
C. class B extends A{B(){System.out.println("i="+i);}}
D. class B{class A{}}
E. class A{}
正确答案:A
(本题原文中没提供正确答案)

574. The following code is entire(全部) contents of a file called Example java,causes precisely(正好) one error during compilation:
1) class SubClass extends BaseClass{
2) }
3) class BaseClass(){
4) String str;
5) public BaseClass(){
6) System.out.println("ok");}
7) public BaseClass(String s){
8) str=s;}}
9) public class Example{
10)Public void method(){
11)subClass s=new SubClass("hello");
12)BaseClass b=new BaseClass("world");
13)}
14)}
Which line would be cause the error?
A. 9
B. 10
C. 11
D. 12
正确答案:C

575. The piece of preliminary analsis(初步的分析) work describes a class that will be used frequently in many unrelated(无关的) parts of a project."The polygon(多边形) object is a drawable.A polygon has vertex(顶点,最高点) informtion stored in a vector,a color,length and width."
Which Data type would be used?
A. Vector
B. int
C. String
D. Color
E. Date
正确答案:A、B、D

576. "The Employee object is a person,An Employee has appointment(约会,指定) store in a vector,a hire date and a number of dependent"short answer:use shortest statement declare a class of Employee.
Fill in the blank.
正确答案:public class Employee extends Person

577. Give the following class defination inseparate(不分开的) source files:
public class Example{
public Example(){
do something}
protected Example(int i){
do something}
protected void method(){
do something}
}
public class Hello extends Example{
member method and member variable
}
Which methods are corrected added to the class Hello?
A. public void Example(){}
B. public void method(){}
C. protected void method(){}
D. private void method(){}
正确答案:A、B、C

578. What right when you try to compile and run the following program?
class Mystery{
String s;
public static void main(String[]args){
Mystery m=new Mystery();
m.go();
}
void Mystery(){
s="constructor";
}
void go(){
System.out.println(s);
}
}
Select the one right answer.
A. this code will not compile
B. this code compliles but throws an exception at runtime
C. this code runs but nothing appears in the standard output
D. this code runs and "constructor"in the standard output
E. this code runs and writes "null"in the standard output
正确答案:E

579. Given this skeleton(框架) of a class currently under construction:
public class Example{
int x,y,z;
public Example (int a,int b){
lots of complex computation
x=a; y=b;
}
public Example(int a,int b,int c){
do everything the same as single argument
version of constructor
including assignment x=a,y=b,z=c
z=c;
}
}
What is the most concise(简明) way to code the "do everything…"part of the constructor taking two arguments?
Fill in the blank.
正确答案:this(a,b);

580. Which are correct class declarations?Assume(假定) in each case that the text constitutes the entire contents of a file called Fred java?
A. public class Fred{
public int x=0;
public Fred(int x){
this.x=x;
}
}
B. public class fred{
public int x=0;
public Fred(int x){
this x=x;
}
}
C. public class Fred extends
MyBaseClass,MyOtherBaseClass{
public int x=0;
public Fred(int xval){
x=xval;
}
}
D. public class Fred{
private int x=0;
private Fred(int xval){ 不能用,除非定义静态的方法
x=xval;
}
}
E. import java awt.*;
public class Fred extends Object{
int x;
private Fred(int xval){
x=xval
}
}
正确答案:A、E

581. Look the inheritance relation(继承关系):
In a source of java have the following line:
woman w=new man();
what statement are corrected?
A. The expression is illegal.
B. Compile corrected but running wrong.
C. The expression is legal.
D. Will construct a woman's object.
正确答案:A

582. The following is a program.
1) class Exsuper{
2) String name;
3) String nick_name;
4)
5) public Exsuper(String s,String t){
6) name = s;
7) nick_name = t;
8) }
9)
10)public string to String(){
11)return name;
12)}
13)}
14)
15)public class Example extends ExSuper{
16)
17)public Example(String s,String t){
18)super(s,t);
19)}
20)
21)Public String to String(){
22)return name +"a.k.a"+nick_name;
23)}
24)
25)public static void main(String args[]){
26)Exsuper a=new Exsuper("First","1^sd")
27)Exsuper b=new Example("second","2^sd")
28)
29)System.out.println("a is"+a.toString());
30)System.out.println("b is"+b.toString());
31)}
32)}
What happens when the user attempts to compile and run this program?
A. A Compiler error occurs at line 21
B. An object of type ClassCastException is thrown at line 27
C. The following output:
a is First
b is second
D. The following output:
a is First
b is Second a.k.a 2^nd
E. The following output:
a is First a.k.a 1^st
b is Second a.k.a 2^nd
正确答案:D

583. Which statement is true about an inner class?
A. It must be anonymous(匿名的)
B. It can not implement an interface
C. It is only accessible in the enclosing(嵌入) class
D. It can access any final variables in any enclosing scope.
正确答案:D

584. Which best describes the requirements of a fully encapsulated(封装) class?
A. Mehtods must not be private.
B. Variables must not be public.
C. The class must be marked final
D. Public methods are all marked final.
E. Modification of the objects state is only possible using method calls.
方法状态仅仅可能用方法调用访问
正确答案:E

585. Given the following class definition:
class A{
public int x;
private int y;
class B{
protected void method(){
}
class C{
private void method2(){
}
}
}
}
class D extends A{
public float z;
}
What can method2() access cirectly,without a reference to another to another instance?
Select all valid answers.
A. the variable x defined in A
B. the variable y defined in A
C. method1 definedin B
D. the variable z defined in D
正确答案:A、B、C

586. Given this interface definition:
interface A{
int method1(int i);
int method2(int j);
}
Which of the following classes implements A
A.class B{
int method1(){…}
int method2(){…}
}
B.class B{
int method1(int i){…}
int method2(int j){…}
}
C. class B implements A{
int method1(int i){…}
int method2(int j){…}
}
D. class B extends A{
int method1(int i){…}
int method2(int j){…}
}

E. class B implements A{
int method1(int i){…}
int method2(int j){…}
}
正确答案:C、E

587. Write a statement for a constructor that invokes the no-args,default constructor in its superclass.
Fill in the blank
正确答案:super();

588. What happens when you try to compile and run the following program?
class Mystery{
String s;
public static void main(String[]args){
Mystery m=new Mystery();
m.go();
}
void Mystery(){
s="constructor";
}
void go(){
System.out.println(s);
}
}
Select the one right answer.
A. this code will not compile
B. this code runs but throws an exception at runtime
C. this code runs but nothing appears in the standard output
D. this code runs but "constructor" in the standard output
E. this code runs and writes "null" in the standard output
正确答案:E

589. Why won't the following class compile?
class A{
private int x;
public static void main(String[]args){
new B();
}
class B{
B(){
System.out.println(x);
}
}
}
Select the one right answer.
A. Class B tries to access a private variable defined in its ouer class
B. Class A attempts to creatc an instance of B when there is no current instance of class A.
C.
正确答案:B

590. What will happen if you try to compile and execute B's main() method?
class A{
int i;
A(int i){
This.i=i*2;
}
}
class B extends A{
public static void main(String[]args){
B b = new B(2); 要调用不带参数的构造函数,但它没有,所以出错。
}
B(int i){
System.out.println(i);
}
}
Select the one right answer.
A. The instance variable i is set to 4
B. The instance variable i is set to 2
C. The instance variable i is set to 0
D. This code will not compile
正确答案:D

override overload
591. Which of the following statements are true?
A. Methods cannot be overriden to be more private
B. Static methods cannot be overloaded
C. Private methods cannot be overloaded
D. An overloaded method cannot throw exceptions vot checked in the base class
正确答案:A

592. What will happen if you attempt to compile and run the following code?
class Base {}
class Sub extends Base {}
class Sub2 extends Base {
public class CEx{
public static void main(String argv[]){
Base b=new Base();
Sub s=(Sub)b;
}
}
Select the one right answer.
A. Compile and run without error
B. Compile time Exception
C. Runtime Exception
正确答案:C

593. Which of the following methods can be legally inserted in place of the comment?
class Base{
public void amethod(int i){ }
}
public class Scope extends Base{
public static void main(String argv[]){
}
//Method Here
}
Select the one right answer.
A. void amethod(int i)throws Exception {} 重写
B. void amethod(long i)throws Exception {} 重载
C. void amethod(long i){} 重载
D. public void amethod(int i)throws Exception {}
正确答案:B、C

594. Gives the following code:
public class MyClass1{
public static void main(String argv[]){ }
/*Modifier at XX*/class MyInner {}
}
What modifiers would be legal at XX in the above code?
A. public
B. private
C. static
D. friend
正确答案:A、B、c

596. What will happen when you attempt to compile and run the following code?
class Base{
private void amethod(int iBase){
System.out.println("Base.anethod");
}
}
class Over extends Base{
public static void main(String argv[]){
Over o=new Over();
int iBase=0;
o.amethod(iBase);
}
public void amethod(int iOver){
System.out.println("Over.amethod");
}
}
Select the right answer.
A. Compile time error complaning that Base.amethod is privste
B. Runtime error complaining that Base.amethod is private
C. Output of "Base.amethod"
D. Output of "Over.amethod"
正确答案:D

597. For a class defined inside a method, what rule gorerns access to the variables of the enclosing method?
A. The class can access any variable
B. The class can only access static variables
C. The class can only access transient variables
D. The class can only access final variables
正确答案:D

598. What will happen when you attempt to compile and run the following code?
import java.io.*;
class Base{
public static void amethod()
throws FileNotFoundException{}
}
public class ExcepDemo extends Base{
public static void main(String argv[]){
ExcepDemo e=new ExcepDemo();
}
public static void amethod(){}
protected ExcepDemo(){
try{
DataInputStream din=
new DataInputStream(System,in);
System.out.println("Pausing");
din readChE();
System.out.println("Continuing");
this amethod();
}catch(IOException ioe){}
}
}
Select the one right answer.
A. Compile time error carsed by protected constructor
B. Compile time error carsed by amethod not declaring Exception
C. Runtime error caused by amethod not declaring Exception
D. Comile and run with output of "Pausing"and"Continuing"after a key is hit
正确答案:D

599. What will happen when you attempt to compile and run this program?
public class Outer{
public String name="Outer";
public static void main(String argv[]){
Inner i=new Inner();
i.showName();
}
End of main
private class Inner{
String name=new String("Inner");
void showName(){
System.out.println(name);
}
}
End of Inner class
}
Select the one teght answer.
A. Compile and run with output of "Outer"
B. Compile and run with output of "Inner"
C. Compile time error because Inner is declared as private
D. Compile time error because of the line creating the instance of lnner
正确答案:D

第八周测试 61题

600. Your chief Software designer has shown you a sketch(草图) of the new Computer parts system she is about to create.At the top of the hierarchy is a Class called Computer and under this are two child classes.One is called LinuxPC and one is called WindowsPC.
The main difference between the two is that one runs the Linux operating System and the other runs the Windows System(of course another difference is that one needs constant re-booting and the other runs reliably),Under the WindowsPC are two Sub classes one called Server and one Called Workstation.How might you appraise your desigmers work?
A. Give the goahead for further design using the curremt scheme
B. Ask for a re-design of the hierarchy with changing the Operating System to a field rather than Class type
C. Ask for the option of WindowsPC to be removed as it will soon be onsolete
D. Change the hierarchy to remove the need for the superfluous(多余的,过剩的) Conputer Class
正确答案:B

601. Which of the following statements are true?
A. An inner class may be defined as static
B. There are No circumstances(环境) where an inner class may be defined as private
C. An anonymous(匿名的) class may have only one constructor
D. An inner class may extend another class
正确答案:A、D

602. Given the following class definition,which of the following methods could be legally placed after the comment?
public classRid{
public void amethod(int j,String s){}
//Here
}
Select the one right answer.
A. public void amethod(String s,int i){}
B. public int amethod(int i,String s){}
C. public void amethod(int i,String mystring s){}
D. public void Amethod(int i,String s){}
正确答案: A、D

603. Given the following class definition which of the following can be legally placed after the comment line?
class Base{
public Base(int i){}
}
public class MyOver extends Base{
public static void main(String arg[]){
MyOver m=new MyOver(10);
}
MyOver(int i){
super(i);
}
MyOver(String s,int i){
this(i);
//Here
}
}
Select the one right answer.
A. MyOver m=new MyOver();
B. super()
C. this("Hello",10);
D. Base b=new Base(10);
正确答案: D

604. Given the following class definition which of the following statements would be legal after the comment?
class InOut{
String s=new String("Between");
public void amethod(final int iArgs){
int iam;
class iam;
class Bicycle{
public void sayHello(){
Here
}
End of bicycle class
}
}//End of amethod
public void another(){
int iOther;
}
}
Selec the one right answer.
A. System.out.println(s);
B. System.out.println(Other);
C. System.out.println(iam);
D. System.out.println(Args);
正确答案: A、D

605. Which of the following statements are true?
A. An interface can only contain method and not variables
B. Interfaces cannot have constructors
C. A class may extend only one other class and implement only one interface
D. Interfaces are the Java approach to addressing its lack of multiple inheritance,but reqrire inplementing classes the functionality of the Interfaces
正确答案: B、D

606. What will happen when you attempt to compile and run the following code?
class Base{
public void Base(){
System.out.println("Base");
}
}
public class In extends Base{
public static void main(String argv[]){
In i=new In();
}
}
Select the one right answer.
A. Compile time error Base is a keyword
B Compile and no output at runtime
C. Output of Base
D. Runtime error Base has no valid constructor
正确答案: B

607. Which of the following statements are true?
A. Constructors cannot have a visibility modifier
B. Constructors can be marked public and protected,but not private
C. Constructors can only have a private return type
D. Constructors are not inherited 可重载不可继承
正确答案: D

608. What will happtn when you attempt tp compile and run the following code?
class Base{
Base(int i){
System.out.println("Base");
}
}
class Severn extends Base{
public static void main(String argv[]){
Severn s=new Severn();
}
void Severn(){
System.out.println("Severn");
}
}
Select the one right answer.
A. Compilation and output of the string "Severn"at runtime
B Compile time error
C. Compilation and no output at runtime
D. Compilation and putout of the string"Base"
正确答案: B

609. Which of the following statements are true?
A. The default constructor has a return type of void
B. The default constructor takes a return type of void
C. The default constructor takes no parameters
D. The default constructor is not created if the class has any constructors of its own
正确答案: C、D

610. Which of the following statements statements are true?
A. All of the variables in an interface are implicitly static
B. All of the variables in an interface are implicitly final
C. All of the methods in an interface are implicitly sbstract
D. A method in an interface can access class level variables
正确答案: A、B、C

611. Which of the following statements are true?
A. A method in an interface must not have a body
B. A class may extend one other class plus at most one interface
C. A class may extend at most one other class plus implement many interfaces
D. An class accesses an interface via the diyword uses
正确答案: A、C

612. You are given a class hierarchy(层次) with an instance of the class Dog.The class Dog is a child of mammal(哺乳动物) and the class Mammal is a child of the class Vertebrate.The class Vertebrate has a method called move which prints out the string "move".The class mammal overrides this method and prints out the string "walks".The class Dog overrides this method and prints out the string"walks on paws".Given an instance of the class Dog.how can you access the ancestor method move in Vertebrate so it prints out the string"move".
A. d.super().super().move();
B. d.parent().parent().move();
C. d.move();
D. none of the above;
正确答案: D

613. Which of the following most closely describes the process of overriding?
A. A class with the same name replaces the functionality of a class defined earlier in the hierarchy
B. A method with the same name completely replaces the functionality of a method earlier in the hierarchy
C. A method with the same name but different parameters gives multiple uses for the same method name
D. A class is prevented from accessing methods in its immediate ancestor
正确答案: B

614. Given the following class definition:
public class Upton{
public static void amethod(int i){
}
public void amethod(int i){
}
//Here
}
Which of the following would be legal to place after the comment?
A. public int amethod(int z){}
B. public int amethod(int i,int j){returm 99;}
C. protected void amethod(long 1){}
D. private void anothermethod(){}
正确答案: B、C、D

615. Given the following class definition:
public class Droitwich{
class one {
private class two{
public void main(){
System.out.println("two");
}
}
}
}
Which of the following statements are true?ar
A. The code will not compile because the classes are nested to more than one level
B. The code will not compile because class two is marked as private
C. The code will not compile and output the string two at runtime
D. The code will compile without error
正确答案: D

616. Which of the following statements are true?
A. constructors cannot be overloaded
B. constructors cannot be overloaden
C. a constructor can return a primitive or an object trference
D. constructor code executes from the current class up the hierarchy to the ancestor class
正确答案: B

617. Which of the following statements are true?
A. A method cannot be overloaded tp be less public in a child class
B. To be overridden a method must have the same name and parameter types
C. To be overridden a method nust have the same name,parameter and return types
D. An overridden method nust ahve the same name,parameter names and parameter types
正确答案: C

618. What will happen when you attempt to compile and run the following code?
class Base{
Base(){
System.out.println("Base");
}
}
public class Checket extends Base{
public static void main(String argv[]){
Checket c=new Checket();
super();
}
Checket(){
System.out.println("Checket");
}
}
Select the one right answer.
A. Compile time error
B. Checket followed by Checket
C. Base followed by Checket
D. runtime error
正确答案: A

619. Which of the following statements are true?
A. Static methods cannot be overriden to be non static
B. Static methods cannot be declared as private
C. Private methods cannot be overloaded
D. An overloaded method cannot throw exceptions not checked in the nase class
正确答案: A

620. What is the result when you compile and run the following code?
class Top{
static void myTop(){
System.out.println("Testing myTop method in Topclass");
}
}
public class Down extends Top{
void myTop(){
System.out.println("Testing myTop method in Down class");
}
public static viod main(String[]args){
Top t=new Down();
t.myTop();
}
}
Select the one right answer.
A. Compile Time error
B. Runtime errorPrints Testing myTop method in Top class on the console
C. Prints Testing myTo[ method in Top class on the console
D. Prints Testing myTop method in Down class on the screen
正确答案: A

621. At what point the following code shows compile time error?
class A{
A(){
System.out.println("Class A constructor");
}
}
class B extends A{
B(){
System.out.println("Class B constructor");
}
}
public class C extends A{
C(){
System.out.println("Class C constructor");
}
public static void main(String args[]){
A a=new A();Line 1
A a1=new B();
Line 2
A a2=new C();Line 3
B b=new C();
Line 4
}
}
Select the one right answer.
A. A a=new A();Line 1
B. A a1=new B();
Line 2
C. A a2=new C();Line 3
D. A b=new C();
Line 4
正确答案: D

622. Select all correct answers about what is the definition of an interface.
A. It is a blue print
B. A new data type
C. Nothing but a class definition
D. To provide multiple inheritance
正确答案: A、B、D

623. What is the result from the following code when you run?
import java,io.*;
calss A {
A()throws Exception{
System.out.println("execrting class A constructor");
throw mew IOException();
}
}
public class B extends A{
B(){
System.out.println("Execrting class B constructor");
}
public static void main(String args[]){
try{
A a=new B();
}catch(Exception c){
System.out.println(c.getMessage());
}
}
}
Select the one right answer.
A. Executing class A constructor
B. Executing class B constrRuntime error A a2=new C();//Line 3
C. Runtime error
D. Compile time error
正确答案: D

624. What is the result from the following code when you run?
import java.io.*;
class A{
A(){
System.out.println("Executing class A construclor");
}
A(int a)throws Exception{
System.out.println("Executing class A constructor");
throw new IOException();
}
}
public class B extends A{
B(){
System.out.println("Executing class B constructor");
}
public static vild main(String args[]){
try{A a=new B();
}catch (Exception e){
System.out.println(e.getMessage());
}
}
}
Select the one right answer.
A. Executing class A constructor followed by Executing class B constructor
B. No output
C. Runtime error
D. Compile time error
正确答案: A

625. If you save and compile the following code.it gives compile time error.How do you correct the compile time error?
public class OuterClass{
finsl String s="Iam outer class member variable";
public void Method(){
String s1="Iam inner class variable";
class InnerClass{
Public viod innerMethod(){
int xyz=20;
System.out.println(s);
System.out.println("Integer value is"+ xyz);
System.out.println(s1);//Illegal.compiler error
}
}
}
}
Select the one right answer.
A. By making s1 as static variable
B. By making s1 as public variable
C. By making s1 as final variable
D. By making InnerClass as static
正确答案: C

626. What is the reason using $ in inner class representation?
A. Because the inner classes are defined inside of amy class
B. Due to the reason thaat inner classes can be defined inside any method
C. This is convention adopted by Sun,to insure that there ix no ambiguity between packages and inner classes.
D. Because if use getClass(),getName() will gives you the error
正确答案: C

627. What will be printed when you execute the code?
class A{
A(){
System.out.println("Class A Constructor");
}
}
public class B exlends A{
B(){
System.out.println("Class B Constructor");
}
public statie void main(String args[]){
B b=new B();
}
}
Select the one right answer.
A. Class A Constructow followed by Class B Constructor
B. Class B Constructow followed by Class B Constructor
C. Compile time error
D. Run time error
正确答案: A

628. Given the piece of code,select the correct to replace at the comment line.
class A{
A(int i){
}
}
public class B extends A{
B(){
//xxxxx
}
public static void main(String args[]){
B b=new B();
}
}
Select the one right answer.
A. super(100);
B. this(100);
C. super();
D. this();
正确答案: A

629. Examine the code below and select the best answer.
class OuterOne{
static classInerOne{}
}
A. we can't make instantce of innerclass outside class OuterOne
B. InnerOne in=new Inner()' will make instance of inner class in another class
C. OuterOne.InnerOne in=new OuterOne.Inner()
D. InnerOne in=new OuterOne().new Inner()'will make instance of inner class in another class
正确答案: C

630. Which of the statements are true?
A. Overridden methods have the asme method name and signature
B. Overridded methods have the asme method name and signature
C. Overridden methods have the asme method name and different signature
D. Overridded methods have the asme method name and different signature
正确答案: A、D

631. What is the result of compiling the following code?
import java.io.*;
classMyExp {
void MyMethod() throws IOException,EOFException{
…………
}
}
class MyExp1 extends MyExp{
void MyMethod(){
…………
}
}
public class MyExp2 extends MyExp1{
voik MyMethod() throws IOException {
…………
}
}
Select the one right answer.
A. Compile time error
B. No compile time error
C. Run-Time error
D. MyMethod() cannot declare IOExceptio in MyExp2 class
正确答案: A、D

632. Select the correct anonymous inner class declaration?
A. new Outer.new Inner
B. new Inner() {}
C. new Inner()
D. Outwe.new Inner()
正确答案: B

633. Which of the following statements are true?
A. An anonymous class cannot have any constructors.
B. An anonymous class can only be created within the body of a method.
C. An anontmous class can only access stati fields of the enclosing class.
D. An anontmous class instantiated and declared in the same place.
正确答案: A、D

634. How can you implement encapsulation?
A. By making methods private and variable private.
B. By making methods are public and variables as private.
C. Make all variable are public and access them using methods.
D. Making all methods and variables as protected.
正确答案: B

635. Given the following class definition,which of the following methods could be legally placed after the comment?
public class Test{
public void anethod(int i,String s){}
//Here
}
Select the one right answer.
A. public void anethod(String s,int i){}
B. public int amethod(int i,String mystring){}
C. public void amethod(int i,String mystring){}
D. public void Amethod(int i,String s){}
正确答案: A、D

636. Given the following class definition,which of the following can be legally placed after the comment line?
class Base{
public Base(int i){
}
}
public class Derived extends Base{
public static void main(String arg[]){
Derived d=new Derived(10);
}
Derived(int i){
super(i);
}
Derived(String s,int i){
this(i);
//Here
}
}
Select the one right answer.
A. Derived d=new Derived();
B. super();
C. this("Hello",10);
D. Base b=new Base(10);
正确答案: D

637. Given the following code fragment:
1) public void create(){
2) Vector mVect;
3) myVect=new Vector();
4)}
Which og the following statements are true?
A. The declaration on line 2 does not allocate memory space for the variable myVect.
B. The declaration on line 2 allocates memory space for a reference to a Vector object.
C. The statement on line 2 creates an object of class Vctor.
D. The statement on line 3 creates an object of class Vctor.
E. The statement on line 3 allocates memory space for an object of class Vector.
正确答案: A、D、E

638. Which statements about inheritance are true?
A. In Java programming language only allows single inheritance.
B. In Java programming language allows a class to implement only one interface.
C. In Java programming language a class cannot extend a class and implement a interface together.
D. In Java programming language single inheritance makes code more reliable.
正确答案:A、D

639. Given the following code:
1) class Person{
2) public void printValue(inti int j){/*…*/}
3) public void printValue(inti i){/*…*/}
4) }
5) puvlic class Teacher extends Person{
6) public void prinValue(){/*…*/}
7) public void prinValue(int i){/*…*/}
8) public static void main(String args[]){}
9) person t=new Teacher();
10)t.trintValue(10);
11)}
12)}
Which method will the statement on line 10 call?
A. on line 2
B. on line 3
C. on line 6
D. on line 7
正确答案:D

640. Given the uncompleted code of a class:
class Person {
String name,department;
int age;
public Person(String n){
name=n; }
public Person(String n, int a){
name=n;
age=a;
}
public Person(String n, String d,int a){
doing the same as two arguments version of constructor
including assignment name=n,age=a
department=d;
}
}
Which expression can be added at the "doing the same as…" part of the constructor?
A. person(n,a);
B. this(Person(n,a));
C. this(n,a);
D. this(name,age).
正确答案:C

641. Given the following code:
public class Parent {
public int addValue(int a,int b){
int s;
s=a+b;
return s;
}
}
class Child extends Parent{
}
Which methods can be added into class Child?
A. int addValue(int a,int b){// do something…}
B. public void addValue(){do something…}
C. public int addValue(int a){
do something…}
D. public int addValue(int a,int b)throws MyException {//do something…}
正确答案:B、C

642. Given the following code:
public class Parent {
int change(){…}
}
class Child extends Parent{
}
Which methods can be added into class Child?
A. public int change(){}
B. int chang(int i){}
C. private int change(){}
D. abstract int chang(){}
正确答案:A、B

643. Given the following code:
class Parent {
String one,two;
public Parent(String a,String b){
one = a;
two = b;
}
public void print(){
System.out.println(one);
}
}
public class Child extends Parent{
public Child(String a,String b){
super(a,b);
}
public void print(){
System.out.println(one+"to"+two);
}
public static void main(String arg[]){
Parent p=new Parent("south","north");
Patent t=new Child("east","west");
p.print();
t.print();
}
}
Which of the following is correct?
A. Cause error during compilation.
B. south
east
C. south to north
east to west
D. sorth to north
east
E. south
east to west
正确答案:E

644. Given the following code:
class Person{
String name.department;
public void printValue(){
System.out.println("name is "+name);
System.out.println("department is"+depqrtment);
}
}
public classnTeacher extendsb Person{
int salary;
public class Teacher extends Person{
int salary;
public void prinValue(){
doing the same as in the parent method printValue()
including print the value of name and department.
System.out.println("salary is"+salary);
}
}
Which expression can be added at the "doing the same as…"part of the method printValue()?
A. printValue();
B. this.printValue();
C. person.printValue();
D. super.printValue();
正确答案:D

645. Given the following code:
1) public class Test{
2) int m,n;
3) public Test(){}
4) public Test(int a){m=a;}
5) public static void main(String arg[]){
6) Test t1,t2;}
7) int j,k;
8) j=0;k=0;
9) t1=new Testz();
10)t2=new Test(j,k);
11)}
12)}
Which line would cause one error during compilation?
A. line 3
B. line 5
C. line 6
D. line 10
正确答案:D

646. In the code if you compile as "java hello4.java" following files will be generated.
1 import java applet.Applet;
2 import java.awt*;
3 import java.awt.event.*;
4 public class hello4 extends Applet {
5 public void int(){
6 add(new myButton("BBB"));
7 }
8 public void paint(Graphics screen){
9 }
10 class myButton extends Button{
11 myButton(String label){
12 super(label);
13 }
14 public String paramString(){
15 return srper.parmString();
16 }
17 }
18 public static void main(String[] args){
19 Frame myFrame=new Frame(
20 "hello4");
21 myFrame.setSize(300,100);
22 Applet myApplet=new hello4();
23 Butten b=new Button("My Button");
24 myApplet.add(b);
25 b setLabel(b getLabel()+"New");
26 myButton b1=new myaButton("PARAMBUTTON");
27 System.out.println(b1.paramString());
28 myFrame.set(myApplet);
29 myFrame.addVisible(true);
30 myFrame.addWindowListener(new WindowAdapter()){
31 public void windowClosing(WindowEvent e){
32 System.exit(0);}});
33}
34 }
End hello4 class.
Select the one reght answer.
A. hello4.class,myButton.class,hello4.lass
B. hello4.class,hello4$myButton.class,hello4$1.class
C. hello4.class.hello4$myButton.class
正确答案:B

647. The following code will give:
1: class Test
2: {
3: void show()
4: {
5: System.out.println("non-static method in Test");
6: }
7: }
8: public class Q3 extends Test
9: {
10:static void show()
11:{
12:System.out.println("Overridden non-static method in Q3");
13:}
14:
15:public static void main(String[]args)
16:{
17:Q3 a=new Q3();
18:}
19:}
Select the one right answer
A. Compilation error at line 3.
B. Compilation error at line 10.
C. No compilation error,but runtime exception at line 3.
D. No compilation error,but runtime exception at line 10.
正确答案:B

648. What will happen if you compile/run the following code?
1: public class Q11
2: {
3: static String str1="main method with String[] args";
4: static String str2="main method with int[] args";
5:
6: public static void main(String[] args)
7: {
8: System.out.println(str1);
9: }
10:
11:public static void main(int[] args)
12:{
13:System.out.println(str2);
14:}
15:}
Select the one right answer.
A. Duplicate method main(),compilation error at line 6;
B. Duplicate method main(),compilation error at line 11;
C. Prints"main method with main String[]args".
D. Prints"main method with main int[]args".
正确答案:C

649. What is the output of the following code?
1: class Test
2: {
3: Test(int i)
4: {
5: System.out.println("Test("+i+")");
6: }
7: }
8:
9: public class Q12
10:{
11:static Test t1=new Test(1);
12:
13:Test t2=new Test(2);
14:
15:static Test t3=new Test(3);
16:
17:public static void main(String[] args)
18:{
19:Q12Q=new Q12();
20:}
21:}
Select the one right answer.
A. Test(1)
Test(2)
Test(3)
B. Test(3)
Test(2)
Test(1)
C. Test(2)
Test(1)
Test(3)
D. Test(1)
Test(3)
Test(2)
正确答案:D

650. What will happen if you compile/run the following code?
1: public class Test
2: {
3: int maxExements;
4:
5: void Test()
6: {
7: maxElements=100;
8: System.out.println(maxElements);
9: }
10:
11:Test(int i)
12:{
13:maxElements=i;
14:System.out.println(maxElements);
15:}
16:
17:public static void main(String[] args)
18:{
19:Test a=new Test();
20:Test b=new Test(999);
21:}
22:}
Select the one right answer.
A. prints 100 and 999.
B. prints 999 and 100.
C. Compilation error at lie 3, variable maxElements was not initialized.
D. Compillation error at line 19.
正确答案:D

651. Which two demonstrate a "has a"relationship?(Choose two)?
A. public interface Person { }
public class Employee extends person{ }
B. public interface Shape { }
public interface Rectandle extends Shape{ }
C. public interface Colorable{ }
public class Shape implements Colorable{ }
D. public class Species{ }
public class Animal{private Species species;}
E. interface Component{}
class Container implements Component{
private Component[]children;
}
正确答案:D、E

652. What is displayed when the following code is executed?
class parent{
private void method1(){
System.out.println("Parent's method1()");
}
public void method2(){
System.out.println("Parent's method2()");
method1();
}
}
class Child extends Parent{
Public void method(){
System.out.println("Child's method1()");
}
public static void main(String args[]){
Parent p=new Child();
p.method2();
}
}
Select the one right avswer.
A. Compile-time error
B. Run-time error
C. Prints:Patent's method2() Parent's method1()
D. Prints:Patent's method2() Child's method1()
正确答案:C

653. What is displayed when the following code is executed?
class Paten{
void method1(){
System.out.println("Parent's method1()");
}
public void method2(){
System.out.println("Parent's method2()");
method1();
}
}
class Child extends Parent{
public void method1(){
System.out.println("Child's method1()");
}
public static void main(String args[]){
Parent p=new Child();
p.method2();
}
}
Select the one right answer.
A. Compile-time error
B. Run-time error
C. Prints:Parent's method2() Parent's method1()
D. Prints:Parent's method2() Child's method1()
正确答案:D

654. What will be the result of compiling the following code?
public class Test{
static int age;
public static void main(String args[]){
age=age+1;
System.out.println("The age is"+age);
}
}
Select the most appropriate answer.
A. Compiles and runs with no output
B. Compiles and runs printing out The age is 1
C. Compiles but generates a runtime error
D. Does not compile
E. Compiles but generates a compile time error
正确答案:B

655. What is the correct declaration of an abstract method that is intended to be public?
Select the most appropriate answer.
A. public abstract void add();
B. public abstract void add() {}
C. public abstract add() {}
D. public virtual add();
正确答案:A

656. Under what situations do you obtain a default constructor?
Select the most appropriate answer.
A. When you define any class;
B. When the class has no other constructors;
C. When you define at least one constructor;
正确答案:B

657. Given the following code:
public the most appropriate answer.
A. public void Test() {…}
B. public Test(){…}
C. public static Test(){…}
D. public static void Test(){…}
正确答案:B

658. Which of the following is a legal return type of a method overloading the following method?
public void add(int a){…}
Select the most appropriate answer.
A. void
B. int
C. Can be anything
正确答案: C

659. Which of the following statemints is correct for a method which is overriding the following method?
public void add(int a){…}
Select the most appropriate answer.
A. the overriding method must return void
B. the overriding method must return int
C. the overriding method can return whatever it likes
正确答案: A

660. Given the following classes defined in separate files?
class Vehicte {
public void dreve(){
System.out.priantln("Vebile.drive");
}
}
class Car extends Vahicle{
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();
v.drivez();
}
}
What will be the effect of compiling and running this class Test?
Select the most appropriate answer.
A. Generates a Compiler error on the statement v=c;
B. Generates runtime error on the statement v=c;
C. Prints out:
Vehicle:drive
Car:drive
D. Prints out:
Vehicte:drive
Car:drive
Vehicle:drive
正确答案: C

第八周测试600-660

661. Where in a constructor,can you place a call to a constructor defined in the super class?
Select the most appropriate answer.
A. Anywhere
B. The first statement in the constructor
C. The last statement in the constructor
D. You can't call super in a constructor
正确答案: B

662. Which variables can an inner class access from the class which encapsulates it?
Select all correct answers.
A. All static variables
B. All final variables
C. All instance variables
D. Only final instance variables
E. Only final static variables
正确答案: A、B、C

663. What class must an inner class extend?
Select the most appropriate answer
A. The top level class
B. The Object class
C. Any class or interface
D. It must extend an interface
正确答案: C

664. Consider the following exanple:
class Firs{
public First(String s){
System.out.println(s);
}
}
public class Second extends First{
public static void main(String args[]){
new Second();
}
}
What os the result of compiling and running the Second class?
Select the most appropriate answer.
A. Nothing happens
B. A string is printed to the standard out
C. An instance of the class First is generated
D. An instance of the class Second is created
E. An exception is raised at runtime stating that there is no null parament constructor class First.
F. The class second will not compile as there is no null parameter constructor in the class First.
正确答案: F

665. Consider the following classes:
public class Test{
public static void test(){
this print();
}
puvlic static void print(){
System.out.println("Test");
}
public static void main(String args[]){
test();
}
}
What is the result of compiling and running this class?
Select all correct answer.
A. The string Test is printed to the standard out.
B. A runting exceptinon is ralsed stating that an object has not been created.
C. Nothing is printed to the standard output.
D. An exception is raised stating that the method test cannot be found.
E. An exception is raised stating that the variable this can only be used within an instance.
F. The class fails to compile stating that the variable this is undefined.
正确答案: F

666. Examine the following class definition:
public class Test{
public static void test(){
print();
}
public static void print(){
System.out.println("Test");
}
public void print(){
System.out.println("Another Test");
}
}
What is the result of compiling this class:
Select the most appropriate answer.
A. A successful compilation.
B. A warning stating that there is a duplicated method.
C. An error stating that there is a duplicated method.
D. An error stating that the method test() will call one or other of the print() methods.
正确答案: C

667. Exanine the following code which includes an inner slass:
public final class Test{
class Inner{
void test(){
if(Test.this.flag);{
sample);{
sample();
}
}
}
private boolean flag=false;
public void sample(){
System.out.println("Sample");
}
public Test(){
(new Inner());test();
}
public static void main(String args[]){
new Test();
}
}
Select the most appropriate answer.
A. Prints out "Sample"
B. Prints produces no output but terminates correctly.
C. Program does not terminate.
D. The program will not compile
正确答案: A

668. Carefully examine the following class:
public class Test{
public static void main(String args[]){
if (true){
Test t=new Test();
System.out.println("Done the test");
}
System.out. println("The end");
}
}
Select the most appropriate answer.
A. Prints out "Done the test"and nothing else.
B. Prints produces no output but terminates correctly.
C. Program does not terminates correctly.
D. The program will not compile.
E. The program generates a runtime exception.
F. The program prints out "The end"and mothing else.
G. The program prints out"Done the test"and "The end"
正确答案: D

669. Given the following code:
class Outer{
class Inner{
}
}
How will you create an instanceof Inner Class out side? Select 2
A.Inner a =newInner();
B.Outer o=new Outer();Inner a=new o.Inner();
C.Outero=new Outer();Outer.Inner a=new o.inner();
D.Outer.Inner a=new Outer().newInner();
正确答案: C D

670.What a static inner class can access ? (selec one)
A.Any variables in the enclosing scope
B.Final variables in the enclosing scope
C.Static variables declared in side the method
D.上述答案都不对
正确答案: D

671. Given the following code:
class Super{
int i=0
Super(String s){
i=10
}
}
class Sub extends Super{
Sub(String s){
i=20;
}
public static void main(String args[]){
Sub b=new Sub("hello");
System.out.printIn(i);
What will be the value of i?
A.Compilation Error
B.Runtime Error
C.0
D.10
E.20
正确答案:E

672. Where will be a 'is a' relationship will occur select one?

A. interface Person
class Employee implements Person
B. interface Shape
interface Rectangle extends Shape
C. interface Component
class Objects implement Component{
Component[]Component;
}
正确答案: B

673.which are the correct forms of Constructors for the class hai?
A. public void hai(int a)
B. hai(int a,int b)
C. public hai(int a)
D. int hai(int c, int d)
E. int hai()
F. int hai(String s)
正确答案: B C

674. Which are the correct forms of overriding for the method void hai(int a,int b)?
A.public void hai(int a,int b)
B.protected void hai(int a,int b)
C.public hai(int a)
D.int hai(int c,int d)
E.int Hai()
F.int hai(String s)
正确答案: A B

675. Given the following code:
1.interface foo
2.{
3.int I=0;
4.}
5.class sreejith implements foo
6.{
7.public static void main(String args[])
8.{sreejith s=new sreejith();
9.int j=0;
10.j=s.I;
11.j=sreejith.I;
12.j=foo.i;
13.s.I=2;
}
}

where will compilation fail?

A.10
B.11
C.12
D.13
E.No error
正确答案:D

676.What is the modifier is used to make a method to be overridden in subclass?
A. final
B. abstract
C. static
D.volatile
正确答案:B

677. Giventhe following code:
public class Outer{

}
What should be inserted at /
// so that the code will compile fine?
A.private class Inner{
static int k;
}
B. static class Inner{
static int k;
}
C.public class Inner{
static int k;
}
D.public abstract class Inner{
public abstract void method();
}
正确答案:B D

678.Which of the following are true about encapsulation?
A.direct access to variables.
B.Access to variables through methods.
C.keeping methods protected.
D.use methods access and modify the variable data.
正确答案:B D

679.Given the following code:
1.class Happy {
2.public static void main(String args[]){
3.public class Sad {
4.public void methodA() {
5.System.out.println("inside sad");
6.}
7.}
8.System.out.println("inside happy");
9.}
10.}
What will be the output?
A. compilation error at line no.3
B. compilation error at no.4
C. compilation error at line no.5
D.compilation succeeds but runtime exeption
E.clean compile and give the output "inside happy"
正确答案: A

680. What is true about consturctors?
A.They initialize all the member variables
B.They initialize all the instance variables
C.If there is no constructor.the compiler includes default constructor.
D.Compiler supplied constructor will invoke the default constructor of the super class.
正确答案: C D

681. Which of the following will describe a perfect ecapsulation?(封装)
A.making all method private
B.making all variables private
C.making class final
D.making methods to public
E.making all variables private and access it through methods
正确答案:B E

682. Given the following code:
Public class base{
String name;
String value;
public base( string n,String m){
name=n;
value=m;
}
public String to String(){
return name;
}
}
public class sub extends base{
public String to String(){
return name+":"+value;
}
public sub(String n, String m){
super(n,m);
}
public static void main(Stromgargs[]){
base b=new base("first","1st");
base b1=new sub ("second","2nd"),
System.out.println(b.toString()+bl.toString());
}
}
What will be the output?
A.compilation error
B.first second:2nd
C.Second:2second:2nd
正确答案:B

683. Given the extends Happy{
class Happy{
public int getLength(){
System.out.println("int version");
}
}
class Life extends Happy{
public long getLength(){
System.out.println("long version");
}
public static void main(String args[]){
Happy e=new Life();
e.getLength();
}
}
Which method gets executed?
A. int version
B. long version
C. compile time error
D. run time exception
E. clean compile but no output
正确答案:C

684. What will you write in the palce of 'xxx'to make instantce of inner class?
class OuterOne{
class InnerONe {}
}
class Test{
OuterOne o=new OuterOne();
//write code to create an instance of the inner class
}
Selct all of the right answers from the flowing.
A. o.InnerOne in=o.new InnerOne();
B. InnerOne in=new o.new InnerOne();
C. OuterOne.InnerOne in =new o. InnerOne();
D. OuterOne.InnerOne in =o.nwe InnerOne();
正确答案: Runnable

SCJP考题12

分类: SCJP考题 2007-10-13 15:37 261人阅读 评论(0) 收藏 举报
1. What will happen when you compile and run this program:
class Test{
pubilc static void main(String[]args){
int length=100;
int[] d=new int[length];
for(int index=0;index<length;index++)
System.out.println(d[index]);
}
}
Select the one right answer.
A. The code will not compile because the int[] array is not declared correctly.
B. The code will compile but will throw an IndexArrayOutOfBoundsException when it runs and nothing will appear in standard output.
C. The code will display the numbers 0 through 99 in the standard output, and then throw an IndexOutOfBoundsException.
D. The code will compile but the println() method will throw a NoSuchMethodException.
E. The code will work fine and display 100 zeroes in the standard output.
正确答案:E

2. How you can use the escape notation u to set the variable c, declared as a char, to the Unicode character whose value is hex 0X30A0?
Fill in the blank.
正确答案:C=/u30a0;

3. Which label name(s) are illegal?
Select all valid answers.
A. here;
B. there;
C. this;
D. that;
E. 2to1odds;
正确答案:C、E

4.What will happen when you attempt to compile and run the following program by passing the Test class to the Java interpreter?
class Test{
public static void main(){
System.out println("hello");
}
}
Select the one right answer.
A. The program does not compile because main() is not defined correctly.
B. The program compiles but when you try to run the interpreter complains that it cannot find the main() method it meeds to run.
C. The program compiles but you cannot run it because the class is not declared as public.
D. The program compiles and runs without an error but does not display anything in the standard output.
E.The program compiles and displays "hello" in the standard output when you run it.
正确答案:B

5.What output is produced by the following program?
class Test{
public static voed main(String args[]){
long size=10;
int[]array=new int[size];
size=20;
System.out.println(array.length);
}
}
Select the one right answer.
A. A compiler error.
B. A runtime error.
C. 10
D. 20
正确答案:A
精解:本题考察的重点是数组大小的指定。
Java 语言中规定用来指定数组长度的数值类型只能是字节型、短整型或整型,而不能是长整型。

6. What output is produced by the following program?
class Test{
public static void nain(String args[]){
char[] a1={'u/0030','/u0031'};
System.out.println(a1[1]);
}
}
Select the one right answer.
A. A compiler error
B. A runtime error
C. 30
D. 31
E. 0
F. 1
正确答案: F

7. True or false? All Java applications and applets require a main() method.
Fill in the blank.
正确答案:False

8. Show six different ways to express the decimal value 28 as an integral literal.
Fill in the blank.
正确答案:28,034, 0x1c, 0x1C, 0X1c, 0X1C

9. There are seven characters, at least one of which must be included to indicate a floating point literal. What are they?
Fill in the blank.
正确答案:'E','e', 'F', 'f', 'D', 'd', '.'

10. True or false? All member variables and all local ariables are automatically initialized in Java.
Fill in the blank.
正确答案: False

11. Which of the following class definitions defines a legal abstract class?
Select all right answer.
A. class Test {
abstract void growl();
}

B. abstract Test {
abstract void growl();
}

C. class abstract Test {
abstract void growl();
}

D. abstract class Test {
abstract void growl();
}

E. abstract class Test {
abstract void growl(){
System.out.println("growl");
}
}

12. What is the proper way of defining a class named Key so that it cannot be subclassed?
A. class Key{}
B. abstract final class Key{}
C. native class Key{}
D. class Key {final;}
E. final class Key{}

13. Given the following code:
class Test {
public static void main(String args[]) {
Cellphone cell=new Cellphone();
cell.emergency();
}
}
class Phone{
final void dia1911(){
//code to dial 911 here…
}
}
class CellPhone extends Phone{
void emergency(){
dia1911();
}
}
What will happen when you try to compile and run the Test class?
A. The code will not compile because phone is not also declared as final.
B. The code will not compile because you cannot invoke a final method from a subclass.
C. The code will compile and run fine.
D. The code will compile but will throw a NoSuchMethodException when Test is run.
E. Phone and CellPhone are fine, but Test will not compile because it cannot create as instance of a class that derives from a class defining a final method.

14. What output is produced by the following program? Note that the instance variable named x is declared private

class Test {
public static void main(String args[]){
AClass ref1 = new AClass (5);
AClass ref2 = new AClass (10);
ref1.getAnShow(ref2);
}
}
class AClass{
private int x;
AClass(int x){
this.x.=x;
}
void getAndShow(AClass ref){
System.out.print(ref.x+" ");
}
}
Select the one reght answer.
A. compiler error.
B. A runtime error.
C. 10

C 来自于同一个类的实例可以相互访问

15. Given the following code:
class Test{
private int m;
public static void fun(){
//some code…
}
}
How can the member variable m be accessible directly in the method fun()?
A. change private int m to protected int m
B. change private int m to public int m
C. change private int m to static int m
D. change private int m to int m

C

16. If a member variable of a class can be accessible only by the same package, which modifier should be used?
A. private
B. public
C. protected
D. no modifier
E. final

D

17. Which one of the following is correct to declare a native method?
A. public native void test();
B. public native void test(){}
C. public void native test();
D. public native test(){}

A

18. Given the following definition of a class:
public class Test{
private float f=1.0f;
int m=12;
static int n=1;
public static void main(String arg[]){
Test t=new Test();
//some code…
}
}
Which of the following usage are legal?
A. t.f
B. this.n
C. Test.m
D. Test.n

A, D

19. Given the following class outline:
class Test{
private int x;
rest of class body
public static void main(String args[]){
implementation of main method
}
}
Which statement is true?
A. x=2 is a valid assignment in the main() method of class Test.
B. Changing private int x to int x would make x=2 a valid assignment in the main() method of class Test.
C. Changing private int x to public int x would make x=2 a valid assignment in the main() method of class Test.
D. Changing private int x to static int x would make x=2 a valid assignment in the main() method of class Test.
E. Changing class Test to public class Test would make x=2 a valid assignment in the main() method of class Test.
正确答案: D

20. What will be the result when you try to compile and run the following cede?
private class Test{
Test(){
int i=100;
System.out.println(i);
}
}
public class Pri extends Test{
static int i=200;
public static void main(String argv[]){
pri p=new pri();
System.out.println(i);
}
}
Select the one right answer.
A. Error at compile time
B. 200
C. 100 following by 200
D. 100
正确答案: A

21. What is the result of executing the following code:
class Test{
public static void main(String args[]){
Test t=new Test();
t.test(1.0,2L,3);
}
void test(double a,double b,short c){
System.out.println("1");
}
void test(float a,byte b,byte c){
System.out.println("2");
}
void test(double a, double b, double c){
System.out.println("3");
}
void test(int a,long b,int e){
System.out.println("4");
}
void test(long a, long b, long c){
System.out.println("5");
}
}
Select the one right answer.
A. 1
B. 2
C. 3
D. 4
E. 5
正确答案: C

22. Given these class definitions:
class Superclass{}
class Subclass1 extends Superclass{}
class Subclass2 extends Superclass{}
And these objects:
Superclass a=new Superclass();
Subclass1 b=new Subclass1();
Subclass2 c=new Subclass2();
Which of the following explains the result of the statement:
b=(Subclass1)c;
Select the one right amswer.
A. Illegal at compile time
B. Legal at compile time but possibly illegal at runtime
C. Definitely legal at runtime
正确答案: A

23. Given these class definitions:
class Superclass{}
class Subclass1 extends Superclass{}
And these objects:
Supetclass a=new Superclass();
Suberclass1 b=new Suberclass1();
Which of the following explains the result of the statement:
b=a;
Select the one right amswer.
A. Illegal at compile time
B. Legal at compile time but possibly illegal at runtime
C. Definitely legal at runtime
正确答案: A

24. What output is produced by the following program?
class Test{
public static void main(String args[]){
char x=65;
char y;
y=(char)(2*x);
System.out.println(y);
}
}
Select the one right amswer.
A. A compiler error
B. A runtime error
C. 130
D. ?(symbol for non-printable character)
正确答案: D

25. What output is produced by the following program?
class Test{
public static void main(String args[]){
int x;
double y=-10.9;
x=(int)y;
System.out.println(x+" ");
y=10.9;
x=(int)y;
System.out.println(x);
}
}
Select the one right amswer.
A. -11 10
B. -11 11
C. -10 10
D. –10 11
正确答案: C

26. What output is produced by the following program?
class Test{
public static void main(String args[]){
try{
byte x=5;
byte y=(byte)(x«2);
System.out.println(y);
}catch(Exception e){
System.out.println("Exception");
}
}
}
Select the one right answer.
A. A compiler error
B. Exception
C. 5
D. 10
E. 15
F. 20
G. 25
正确答案: F

27. What output is produced by the following program?
class Test{
public static void main(String args[]){
try{
byte x=-32;
byte y=(byte)(x»>2);
byte z=(byte)(x + y);
System.out.println(y);
}catch(Exception e){
System.out.println("Exception");
}
}
}
Select the one right amswer.
A. A compiler error
B. Exception
C. -4
D. -8
E. -16
F. -32
G. None of the above
正确答案: D

28. Analyze these two consecutive lines of code:
float f=3.2;
int i=f;
Select all valid answer.
A. this code would not compile
B. this code would compile and i would be set to 3
C. the second line could compile if it were written instead as: int i =(byte)f;
D. the first line could compile if it were written instead as: float f=3.2F;
正确答案: A、C、D

29. Which of the following lines of code will compile without error?
A. int i=0;
if(i){
System.out.println("Hello");
}
B. boolean b=true;
boolean b2=true;
if(b==b2){
System.out.println("So true");
}
C. int i=1;
int j=2;
if(i==1 || j==2)
System.out.println("OK");
D. int I=1;
int j=2;
if(i==1 &| j==2)
System.out.println("OK");

正确答案: B、C

30. Given the following classes which of the following will compile without error?
interface IFace{}
class CFace implements IFace{}
class Base{}
public class Test extends Base{
public static void main(String argv[]){
Test ob=new Test();
Base b=new Base();
Object o1=new Object();
IFace o2=new CFace();
}
}
Select the one right answer.
A. o1=o2;
B. b=ob;
C. ob=b;
D. o1=b;
正确答案: A、B、D

31. Which of the following are valid statements?
A. System.out.println(1+1);
B. int i=2+'2';
C. byte b=255;
正确答案: A、B

SCJP考题13

分类: SCJP考题 2007-10-13 15:41 320人阅读 评论(0) 收藏 举报
子类的构造函数会自动调用父类无参数的构造函数

在重写中,所谓子类中方法的访问控制不能比父类中方法的访问控制范围窄是指:
Ø 一个package方法可以被重写为package、protected和public的
Ø 一个protected方法可以被重写为protected和public的
Ø 一个public方法只可以被重写为public的
局部变量不可以使用任何访问修饰符
局部变量也不可以使用除final以外的任何其它非访问修饰符
任何在局部变量上使用不法修饰符的代码都会得到一个编译错误
abstract不能与final一起使用
abstract不能与private一起使用
abstract不能与synchronized一起使用
abstract不能与native一起使用
abstract不能与strictfp一起使用
abstract不能与static一起使用
最后:abstract不能用于成员变量

Which two of the following are legal definitions for non-nested classes and interface?(select two)
A static public interface Foo()
B abstract public class Foo()
C protected interface Foo()
D final abstract class Foo()
E final public class Foo()
正确答案:B E

Public class MyOuter{
Public static class MyInner{
Public static void foo(){}
}
}
正确声明MyInner类:MyOuter.MyInner m=new MyOuter.MyInner()

注意: MyInner m=new MyOuter.MyInner()是不对的!!

Section:Operators and Assignments
Problem[10]
Which statements are true concerning the
effect of the » and »> operators?
[Select All]
[1]For non-negative values of the left
operand, the » and »> operators will
have the same effect.
[2]The result of (-1 » 1) is 0.
[3]The result of (-1 »> 1) is -1.
[4]The value returned by »> will never
be negative as long as the value of the
right operand is equal to or greater than
1.
[5]When using the » operator, the
leftmost bit of the bit representation
of the resulting value will always be the
same bit value as the leftmost bit of the
bit representation of the left operand.
[Correct Choices]
[1] true
[2] false
[3] false
[4] true
[5] true

Section:Overloading Overriding Runtime
Type and Object Orientation
Problem[22]
What will be written to the standard
output when the following program is run?
class Base {
int i;
Base() {
add(1);
}
void add(int v) {
i += v;
}
void print() {
System.out.println(i);
}
}
class Extension extends Base {
Extension() {
add(2);
}
void add(int v) {
i += v*2;
}
}
public class Qd073 {
public static void main(String
args[]) {
bogo(new Extension());
}
static void bogo(Base b) {
b.add(8);
b.print();
}
}
[Select One]
[1]9
[2]18
[3]20
[4]21 ///
[5]22
[Correct Choice]
5

Section:Language Fundamentals
Problem[21]
What does the value returned by the
method getID() found in class
java.awt.AWTEvent uniquely identify?
[Select One]
[1]The particular event instance.
[2]The source of the event.
[3]The set of events that were triggered
by the same action.
[4]The type of event.
[5]The type of component from which the
event originated.
[Correct Choice]
4

Section:Declarations and Access Control
Problem[23]
Which lines of code are valid
declarations of a native method when
occurring within the declaration of the
following class?
public class Qf575 {
// insert declaration of a native
method here
}
[Select All]
[1]native public void
setTemperature(int kelvin);
[2]private native void
setTemperature(int kelvin);
[3]protected int native
getTemperature();
[4]public abstract native void
setTemperature(int kelvin);
[5]native int setTemperature(int kelvin)
{}
[Correct Choices]
[1] true
[2] true
[3] false
[4] false
[5] false

Section:Operators and Assignments
Problem[66]
The 8859-1 character code for the uppercase
letter A is 65. Which of these code fragments
declare and initialize a variable of type char
with this value?
[Select All]
[1]char ch = 65;
[2]char ch = '/65';
[3]char ch = '/0041';
[4]char ch = 'A';
[5]char ch = "A";
[Correct Choices]
[1] false
[2] false
[3] false
[4] true
[5] false

Section:Threads
Problem[63]
Given the following code, which
statements concerning the objects
referenced through the member variables
i, j and k are true, given that any thread
may call the methods a, b and c at any
time?
class Counter {
int v = 0;
synchronized void inc() { v++; }
synchronized void dec() { v—; }
}
public class Q7ed5 {
Counter i;
Counter j;
Counter k;
public synchronized void a() {
i.inc();
System.out.println("a");
i.dec();
}
public synchronized void b() {
i.inc(); j.inc(); k.inc();
System.out.println("b");
i.dec(); j.dec(); k.dec();
}
public void c() {
k.inc();
System.out.println("c");
k.dec();
}
}
[Select All]
[1]i.v is guaranteed always to be 0 or
1.
[2]j.v is guaranteed always to be 0 or
1.
[3]k.v is guaranteed always to be 0 or
1
[4]j.v will always be greater than or
equal to k.v at any give time.
[5]k.v will always be greater than or
equal to j.v at any give time.
[Correct Choices]
[1] true
[2] true
[3] false
[4] false
[5] false

Section:The java.io package
Problem[61]
Given that file is a reference to a File
object that represents a directory,
which code fragments will succeed in
obtaining a list of the entries in the
directory?
[Select All]
[1]Vector filelist = ((Directory)
file).getList();
[2]String[] filelist = file.directory();
[3]Enumeration filelist =
file.contents();
[4]String[] filelist = file.list();
[5]Vector filelist = (new
Directory(file)).files();
[Correct Choices]
[1] false
[2] false
[3] false
[4] true
[5] false

Section:Language Fundamentals
Problem[58]
Which statements concerning the event
model of the AWT are true?
[Select All]
[1]At most one listener of each type can
be registered with a component.
[2]Mouse motion listeners can be
registered on a List instance.
[3]There exists a class named
ContainerEvent in package
java.awt.event.
[4]There exists a class named
MouseMotionEvent in package
java.awt.event.
[5]There exists a class named
ActionAdapter in package java.awt.event.
[Correct Choices]
[1] false
[2] true
[3] true
[4] false
[5] false

Section:The java.awt package - Layout
Problem[57]
What will be the appearance of an applet
with the following init() method?
public void init() {
add(new Button("hello"));
}
[Select One]
[1]Nothing appears in the applet.
[2]A button will cover the whole area of
the applet.
[3]A button will appear in the top left
corner of the applet.
[4]A button will appear, centered in the
top region of the applet.
[5]A button will appear in the center of
the applet.
[Correct Choice]
4

Problem[55]
Which statements concerning the switch
construct are true?
[Select All]
[1]All switch statements must have a
default label.
[2]There must be exactly one label for
each code segment in a switch statement.
[3]The keyword continue can never occur
within the body of a switch statement.
[4]No case label may follow a default
label within a single switch statement.
[5]A character literal can be used as a
value for a case label.
[Correct Choices]
[1] false
[2] false
[3] false
[4] false
[5] true

Problem[51]
Which statements concerning the methods
notify() and notifyAll() are true?
[Select All]
[1]Instances of class Thread have a
method called notify().
[2]A call to the method notify() will
wake the thread that currently owns the
monitor of the object.
[3]The method notify() is synchronized.
[4]The method notifyAll() is defined in
class Thread.
[5]When there is more than one thread
waiting to obtain the monitor of an
object, there is no way to be sure which
thread will be notified by the notify()
method.
[Correct Choices]
[1] true
[2] false
[3] false
[4] false
[5] true

504. What letters get written to the standard output with the following code?
class Test{
public static void main(String[] args){
try {
method();
} catch(Exception e){}
}
static void method(){
try {
wrench();
System.out.println("a");
} catch (ArithmeticExeption e){
System.out.println("b");
}finally{
System.out.println("c");
}
Syatem.out.println("d");
}
static void wrench(){
throw new NullPointerException();
}
}
Select all valid answer.
A. "a"
B. "b"
C. "c"
D. "d"
E. none of there
正确答案: C
511. What appears in the standard output if the method named problem() in the code below throws an instance of class Exception when the method named trythis() is invoked?
public void trythis(){
try{
System.out.println("1");
problem();
}catch(RuntimeException x){
System.out.println("2");
return;
}catch(Exception x){
System.out.println("3");
return;
}finally{
System.out.println("4");
}
System.out.println("5");
}
Select all valid answers.
A. "1"
B. "2"
C. "3"
D. "4"
E. "5"
正确答案: A、C、D

518. What will be printed out if you attempt to compile and run the following code?
int i=9;
switch(i){
default:
System.out.println("default");
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
case 2:
System.out.println("two");
Select the one right answer.
A. default
B. default, zero
C. error default clause not defined
D. no output displayed
正确答案: B

522. What will happen when you attempt to compile and run the following code?
public class MySwitch{
public static void main(String argv[]){
MySwitch ms=new MySwitch();
ms.anethod();
}
public void anethod(){
int k=10;
switch(k){
//Put thedefault at the botton, not here
defauly:
System.out.println("This is thedefault output");
break;
case 10:
System.out.println("ten");
case 20:
System.out.println("twenty");
break;
}
}
}
Select the one reght answer.
A. None of these options.
B. Compile time error target of switch must be an integral type.
C. Compile and run with output "This is the default output".
D. Compile and run with output "ten twenty".
正确答案: D

542. Given the following code:
class Test{
public static void main(String args[]){
System.out.println(hai());
}
static int hai(){
try{
return 1;
}
catch(Exception e){
System.out.println("Exception");
}
finally{
System.out.println("Finally");
return 2;
}
}
}
What will be the out put?
A. Compilation Error void main Can't return any value.
B. Prints Exception.
C. Prints Exception Finally.
D. Prints Finally and 1.
E. Prints Finally and 2.
正确答案:E

545. Given the following code:
class Test{
public static void main(String args[]){
try{
//ProtocoIException
}catch(ProtocalException e){
System.out.println("I");
}catch(IOException e){
System.out.println("E");
}finally{
System.out.println("F");
}
}
}
If a ProtocoIException occurs in try block. what will be the output? Select all.
A. I
B. E
C. F
D. Compilation Error says that there is no matching catch block
正确答案:A、C

529. What is the result when you compile and run the following code?
public class Test{
static void throwMethod(){
System.out.println("Inside throw Method.");
throw new IllegalAccessException("demo");
}
public static void main(String args[]){
try{
throwMethod();
}
catch(IllegallAccessException e){
System.out.Println("Caught"+e);
}
}
}
Select the one right answer.
A. Compilation error
B. Runtime error
C. Compile successfully, nothing is printed
D. Inside throwMethod. followed by caught: java.lang.IllegalAccessExcption:demo
正确答案: A

626. What is the reason using $ in inner class representation?
A. Because the inner classes are defined inside of amy class
B. Due to the reason that inner classes can be defined inside any method
C. This is convention adopted by(被。。。。采用) Sun,to insure(确保) that there is no ambiguity(含糊的) between packages and inner classes.
D. Because if use getClass(),getName() will gives you the error
正确答案:C

623. What is the result from the following code when you run?
import java,io.*;
calss A {
A()throws Exception{
System.out.println("execrting class A constructor");
throw mew IOException();
}
}
public class B extends A{
B(){
System.out.println("Execrting class B constructor");
}
public static void main(String args[]){
try{
A a=new B();
}catch(Exception c){
System.out.println(c.getMessage());
}
}
}
Select the one right answer.
A. Executing class A constructor
B. Executing class B constructor
C. Runtime error
D. Compile time error
正确答案:D

Which three are valid declarations of a float?
A float f1=054321
B float f2=314e7
C float f3=123456789
D float f4=2.182D
E float f5=2002.02
F float f6=1.732F
正确答案:ACF

633. Which of the following statements are true?
A. An anonymous(匿名的) class cannot have any constructors.
B. An anonymous class can only be created within the body of a method.
C. An anontmous class can only access static fields of the enclosing class.
D. An anontmous class instantiated and declared in the same place.
正确答案: A、D

646. In the code if you compile as "java hello4.java" following files will be generated.
1 import java applet.Applet;
2 import java.awt*;
3 import java.awt.event.*;
4 public class hello4 extends Applet {
5 public void int(){
6 add(new myButton("BBB"));
7 }
8 public void paint(Graphics screen){
9 }
10 class myButton extends Button{
11 myButton(String label){
12 super(label);
13 }
14 public String paramString(){
15 return srper.parmString();
16 }
17 }
18 public static void main(String[] args){
19 Frame myFrame=new Frame(
20 "hello4");
21 myFrame.setSize(300,100);
22 Applet myApplet=new hello4();
23 Butten b=new Button("My Button");
24 myApplet.add(b);
25 b setLabel(b getLabel()+"New");
26 myButton b1=new myaButton("PARAMBUTTON");
27 System.out.println(b1.paramString());
28 myFrame.set(myApplet);
29 myFrame.addVisible(true);
30 myFrame.addWindowListener(new WindowAdapter()){
31 public void windowClosing(WindowEvent e){
32 System.exit(0);}});
33}
34 }
End hello4 class.
Select the one reght answer.
A. hello4.class,myButton.class,hello4.lass
B. hello4.class,hello4$myButton.class,hello4$1.class
C. hello4.class.hello4$myButton.class
正确答案:B

649. What is the output of the following code?
1: class Test
2: {
3: Test(int i)
4: {
5: System.out.println("Test("+i+")");
6: }
7: }
8:
9: public class Q12
10:{
11:static Test t1=new Test(1);
12:
13:Test t2=new Test(2);
14:
15:static Test t3=new Test(3);
16:
17:public static void main(String[] args)
18:{
19:Q12Q=new Q12();
20:}
21:}
Select the one right answer.
A. Test(1)
Test(2)
Test(3)
B. Test(3)
Test(2)
Test(1)
C. Test(2)
Test(1)
Test(3)
D. Test(1)
Test(3)
Test(2)
正确答案:D

648. What will happen if you compile/run the following code?
1: public class Q11
2: {
3: static String str1="main method with String[] args";
4: static String str2="main method with int[] args";
5:
6: public static void main(String[] args)
7: {
8: System.out.println(str1);
9: }
10:
11:public static void main(int[] args)
12:{
13:System.out.println(str2);
14:}
15:}
Select the one right answer.
A. Duplicate(复制) method main(),compilation error at line 6;
B. Duplicate method main(),compilation error at line 11;
C. Prints"main method with main String[]args".
D. Prints"main method with main int[]args".
正确答案:C
652. What is displayed when the following code is executed?
class parent{
private void method1(){
System.out.println("Parent's method1()");
}
public void method2(){
System.out.println("Parent's method2()");
method1();
}
}
class Child extends Parent{
Public void method1(){
System.out.println("Child's method1()");
}
public static void main(String args[]){
Parent p=new Child();
p.method2();
}
}
Select the one right avswer.
A. Compile-time error
B. Run-time error
C. Prints:Patent's method2() Parent's method1()
D. Prints:Patent's method2() Child's method1()
正确答案:C

653. What is displayed when the following code is executed?
class Paten{
void method1(){
System.out.println("Parent's method1()");
}
public void method2(){
System.out.println("Parent's method2()");
method1();
}
}
class Child extends Parent{
public void method1(){
System.out.println("Child's method1()");
}
public static void main(String args[]){
Parent p=new Child();
p.method2();
}
}
Select the one right answer.
A. Compile-time error
B. Run-time error
C. Prints:Parent's method2() Parent's method1()
D. Prints:Parent's method2() Child's method1()
正确答案:D

666. Examine the following class definition:
public class Test{
public static void test(){
print();
}
public static void print(){
System.out.println("Test");
}
public void print(){
System.out.println("Another Test");
}
}
What is the result of compiling this class:
Select the most appropriate answer.
A. A successful compilation.
B. A warning stating that there is a duplicated method.
C. An error stating that there is a duplicated method.
D. An error stating that the method test() will call one or other of the print() methods.
正确答案:C

679.Given the following code:
1.class Happy {
2.public static void main(String args[]){
3.public class Sad { 不能是public,不写或者是final
4.public void methodA() {
5.System.out.println("inside sad");
6.}
7.}
8.System.out.println("inside happy");
9.}
10.}
What will be the output?
A. compilation error at line no.3
B. compilation error at no.4
C. compilation error at line no.5
D.compilation succeeds but runtime exeption
E.clean compile and give the output "inside happy"
正确答案 A

525. The thread run() method has the following code, what is the result when the thread runs?
try{
sleep(200); 不会扔出一个IOException
System.out.println("Printing from thread run()method");
}catch(IOException ie){}
Selet the one right answer.
A. Compile time error
B. Prints on the console Printing from thread run() method
C. At line 2 the thread will be stop running and resumes after 200 milliseconds and prints Printing from thread run() method
D. At line 2 the thread will be stop running and resumes exactly 200 milliseconds elapsed
正确答案: A

523. What will happen when you attempt to compile and run the following code?
public class Test{
static public int i=10;
public static void main(String argv[]){
switch(i){
default:
System.out.println("no value given");
case 1:
System.out.println("one");
case 10:
System.out.println("ten");
case 5:
System.out.println("five");
}
}
}
正确答案:ten five

如果i=6 输出:no value given one ten five

10.What output is produced by the following program?
class Test{
public static void main(String args[]){
long size=10;
int[]array=new int[size];
size=20;
System.out.println(array.length);
}
}
Select the one right answer.
A. A compiler error.
B. A runtime error.
C. 10
D. 20
正确答案:A

28. What output is produced by the following program? Note that the main() method is not declared public.
class Test{
static void main(String args[]){
System.out.println("OK");
}
}
Select the one right answer.
A. A compiler error.
B. A runtime error.
C. OK
正确答案: C

29. What output is produced by the following program? Note that the main() method is not declared static.
class Test{
public void main(String args[]){
System.out.println("OK");
}
}
Select the one right answer.
A. A compiler error.
B. A runtime error.
C. OK
正确答案: B

33. True or false? In Java primitives(原始的) are passed by value and objects are passed by reference. 数组
Fill in the blank.
正确答案: False

2.what is the numerical range of a char ?(choose one)
A -128 to 127
B –(2^15)to(2^15)-1
C 0 to 32767
D platform dependent
E 0 to 65535

正确答案:E

4. which two of the following are legal declarations for nonnested (非嵌套)class and interface (choose two)
A final abstract class test{} final 和abstract 不能同时用在一个类中
B public static interface test{} 接口和类不能声明为static
C final public class test{}
D protected abstract class test{}
E protected interface test{} protected 不能标识类和接口
F abstract public class test{}

正确答案C E

5.How many of the following are legal method declarations?
A protected abstract void m1();
B static final void m1(){}
C transient private native void m1(){} transient 只适用于变量声明,而不适用于类和方法声明。
D synchronized public final void m1(){}
E private native void m1();
F static final synchronized protected void m1(){}
正确答案A B D E F

6.which two are valid declarations within an interface?(choose two)
A public static short stop=23;
B protected short stop=23;
C transient short stop=23;
D final void madness(short stop);
E public Boolean madness(long bow);
F static char madness(double duty);
接口不能是protected, transient,final , static

正确答案A E
7.Which three are valid method signatures in an interface?(choose three)
A private int get Area(); 接口方法必须是public或不写
B public float getVol(float x);
C public void main(String[] args);
D public static void main(String[] args); 去了static就行了
E Boolean setFlag(Boolean [] test[]);
正确答案:B C E

4. which two of the following are legal declarations for nonnested (非嵌套)class and interface (choose two)
A final abstract class test{} final 和abstract 不能同时用在一个类中
B public static interface test{} 接口和类不能声明为static
C final public class test{}
D protected abstract class test{}
E protected interface test{} protected 不能标识类和接口
F abstract public class test{}

C
E

241. What output is produced by the following program?
class Test{
public static void main(String args[]){
System.out.println(Double.isNaN(3.0%0));
System.out.print("");
System.out.println(Double.isNaN(3.0/0));
}
}
Select of the right answers.
A. false false
B. false ture
C. ture false
D. true true
正确答案:C

242. What output is produced by the following program?
class Test{
public static void main(String args[]){
try{
double x=64.0;
double y=0.0;
System.out.println(x%y==x%y);
}cateh(Exception e){
System.out.println("Exception");
}
}
}
Select all of the right answers from the flowing
A. A compiler error
B. Exception
C. true
D. fatse
正确答案:D

243. What output is produced by the following program?
class Test{
public static void main(String args[]){
try{
System.out.println(Float.NaN==Float NaN);
System.out.println(""+
(Float.POSITIVE.INFINITY==Float.POSITIVE_INFINITY));
}catch(Exception e){
System.out.println("Exception");
}
}
}
Select all of the right answers
A. A compiler error
B. Exception
C. true true
D. fatse false
正确答案:D

Public class TestThread extends Thread{
Public static void main(String[] args){
TestThread t=new TestThread();
t.run();
}
Public void run(){
For(int i=1;i<4;i++){
System.out.println(i+” ”);
}
}
}

输出答案是:1 2 3
Which two are true about a non-static method-local inner class(select two)?
A it cannot implement an interface
B it can be marked abstract
C it can be marked static
D it must be marked final
E it can access all members of the enclosing class
正确答案:B E

Public class wrap {
Public static void main(String[] args){
String s=”343”;
//insert code here
}

}
Which three lines inseted independently at line 4 will cause complier errors?
A long f1 =Long.longValue(S);
B long f2 = Long.valueOf(s);
C long f3 = new Long(343).longValue();
D long f4 = Long.parseLong(343);
E long f5 = Long.valueOf(s).longValue();
正确答案:A B D

247. What output is produced by the following program?
class Test{
public static void main(String args[]){
try{
int x=-7;
System.out.println(x/2+""+(x»1));
}catch(Exception e){
System.out.println("Exception");
}
}
}
Select all of the right answers from the flowing.
A. A compiler error
B. Exception
C. -3 -3
D. -3 -4
E. -4 -4
F. None of the above
正确答案: D

Given the flowing:
Public class Test{
Public static void main(String[] args){
Int[ ][ ][ ] x=new int [3][ ][ ];
Int I,j;
X[0]=new int[4][ ];
X[1]=new int[2][ ];
X[2]=new int[5][ ];
For(i=0;i<[i].length;j++){
For(j=0;j<x[i].length;j++){
X[i][j]=new int[i+j+1];
System.out.println(“Size=”+x[i][j].length);
}
}
}
}
How many lines of output will be producted?(choose one)
A 7
B 9
C 11
D 13
E compilation fails
F an exception is thrown at runtime

C

712. There are 20 threads are waiting in the waiting pool with same priority. how can you invokes 15th thread from the wailing pool?
A. By calling resume() method
B. By calling interrupt() method
C. Calling call() method
D. By calling notify(15)method on the thread instance
E. None of the above
怎么调用!!是不知道么???

721. What happens when you try to compile and run the following application?
public class Test{
public static void main(String[] args){
new Test();
}
Test(){
Test alias1=this;
Test alias2=this;
synchronized(alias1){
try{
slias2.wait();
System.out.println("DONE WAITING");
}
Catch(InterruptedException e){
System.out.println("INTERR UPTED");
}
catch(Exception e){
System.out.println("OTHER EXCEPTION");
}
finally{
System.out.println("FINALLY");
}
}
System.out.println("ALL DONE");
}
}
Choose all correct options.
A. The application compiles but doesn't print anything.
B. The application compiles and print"DONE WAITING"
C. The application compiles and print "FINALLY"
D. The application compiles and print "ALL DONE"
E. The application compiles and print "INTERRUPTED"
正确答案: A

726. What is the result of compiling and executing the following Java class:
public class Test extends Thread{
public void run(){
System.out.println("In run");
suspend();
resume();
System.out.println("Leaving run");
}
public static void main(Syring args[]){
(new Test()).start();
}
}
Select the most appropriate answer.
A. Compilation will fail in the method main.
B. Compilation will fail in the method run.
C. A warning will be generated for method run.
D. The string" In run" will be printed to standard out.
E. Both strings will be printed tp standard out.
F. Nothing will happen.
正确答案: D
我觉得是E

687. What appears in the standard output when you run the Dots class?
class Test impltements Runnable{
DotThread t;
public static void main(String[]args){
Test d=new Test();
d.t=new DotTgread();
}
public void init(){
t.start();
t=new DashThread().start();
}
}
class DotThread extends Thread{
public void run(){
for(int index=0;index<100;index++)
System.out.print(".");
}
}
class DashThread extends Thread{
public void run(){
for(int index=0;index<100;index++)
System.out.print("-");
}
}
Select the one right answer.
A. nothing
B. 100 dots(.)
C. 200 dots(.)
D. 100 dashes(-)
E. 100 dots(.)and 100 dashes(-)

Which of the following Collections classes can return object references in the order they were added?(choose one)
A java.util.Collection
B java.util.Hashtable
C java.util.Map
D java.util.Vector
正确答案:D

What kind of Stream is the Stream is the System.out.object??(choose one)
A java.io.printStream
B java.io.TerminalStream
C java.io.FileWriter
D java.io.SystemStream
正确答案:A

Which of the following events has a matching adapter class that implements the appropriate listener interface?(choose two)
A java.awt.event.FocusEvent
B java.awt.event.KeyEvent
C java.awt.event.ItemEvent
D java.awt.event.ActionEvent
正确答案:A B

Which of the following are methods of the Collection interface?
A isEmpty()
B getIndex();
C iterator()
D toArray()
E isFull()
正确答案:A C D

Which of the following AWT components can generate an ActionEvent?(choose one)
A java.awt.List
B java.awt.Canvas
C java.awt.Panel
D java.awt.Scrollbar
正确答案:A

Which of the following will print “NULL” when the object reference tmp has the null value?(choose one)
A if(temp==null) System.out.println(“NULL”);
B if(temp=null) System.out.println(“NULL”);
C if(temp.equal(null)) System.out.println(“NULL”);
D if(x instanceof null) System.out.println(“NULL”);
正确答案: A

SCJP考题14

分类: SCJP考题 2007-10-13 15:43 367人阅读 评论(0) 收藏 举报
615. Given the following class definition:
public class Droitwich{
class one {
private class two{
public void main(){
System.out.println("two");
}
}
}
}
Which of the following statements are true?
A. The code will not compile because the classes are nested to more than one level
B. The code will not compile because class two is marked as private
C. The code will not compile and output the string two at runtime
D. The code will not compile without error
正确答案: D

623. What is the result from the following code when you run?
import java,io.*;
calss A {
A()throws Exception{
System.out.println("execrting class A constructor");
throw mew IOException();
}
}
public class B extends A{
B(){
System.out.println("Execrting class B constructor");
}
public static void main(String args[]){
try{
A a=new B();
}catch(Exception c){
System.out.println(c.getMessage());
}
}
}
Select the one right answer.
A. Executing class A constructor
B. Executing class B constructor
C. Runtime error
D. Compile time error

626. What is the reason using $ in inner class representation?
A. Because the inner classes are defined inside of amy class
B. Due to the reason that inner classes can be defined inside any method
C. This is convention adopted by(被。。。。采用) Sun,to insure(确保) that there is no ambiguity(含糊的) between packages and inner classes.
D. Because if use getClass(),getName() will gives you the error

633. Which of the following statements are true?
A. An anonymous(匿名的) class cannot have any constructors.
B. An anonymous class can only be created within the body of a method.
C. An anontmous class can only access static fields of the enclosing class.
D. An anontmous class instantiated and declared in the same place.
正确答案: A、D

646. In the code if you compile as "java hello4.java" following files will be generated.
1 import java applet.Applet;
2 import java.awt*;
3 import java.awt.event.*;
4 public class hello4 extends Applet {
5 public void int(){
6 add(new myButton("BBB"));
7 }
8 public void paint(Graphics screen){
9 }
10 class myButton extends Button{
11 myButton(String label){
12 super(label);
13 }
14 public String paramString(){
15 return srper.parmString();
16 }
17 }
18 public static void main(String[] args){
19 Frame myFrame=new Frame(
20 "hello4");
21 myFrame.setSize(300,100);
22 Applet myApplet=new hello4();
23 Butten b=new Button("My Button");
24 myApplet.add(b);
25 b setLabel(b getLabel()+"New");
26 myButton b1=new myaButton("PARAMBUTTON");
27 System.out.println(b1.paramString());
28 myFrame.set(myApplet);
29 myFrame.addVisible(true);
30 myFrame.addWindowListener(new WindowAdapter()){
31 public void windowClosing(WindowEvent e){
32 System.exit(0);}});
33}
34 }
End hello4 class.
Select the one reght answer.
A. hello4.class,myButton.class,hello4.lass
B. hello4.class,hello4$myButton.class,hello4$1.class
C. hello4.class.hello4$myButton.class
正确答案:B

647. The following code will give:
1: class Test
2: {
3: void show()
4: {
5: System.out.println("non-static method in Test");
6: }
7: }
8: public class Q3 extends Test
9: {
10:static void show()
11:{
12:System.out.println("Overridden non-static method in Q3");
13:}
14:
15:public static void main(String[]args)
16:{
17:Q3 a=new Q3();
18:}
19:}
Select the one right answer
A. Compilation error at line 3.
B. Compilation error at line 10.
C. No compilation error,but runtime exception at line 3.
D. No compilation error,but runtime exception at line 10.
正确答案:B

649. What is the output of the following code?
1: class Test
2: {
3: Test(int i)
4: {
5: System.out.println("Test("+i+")");
6: }
7: }
8:
9: public class Q12
10:{
11:static Test t1=new Test(1);
12:
13:Test t2=new Test(2);
14:
15:static Test t3=new Test(3);
16:
17:public static void main(String[] args)
18:{
19:Q12Q=new Q12();
20:}
21:}
Select the one right answer.
A. Test(1)
Test(2)
Test(3)
B. Test(3)
Test(2)
Test(1)
C. Test(2)
Test(1)
Test(3)
D. Test(1)
Test(3)
Test(2)
正确答案:D

648. What will happen if you compile/run the following code?
1: public class Q11
2: {
3: static String str1="main method with String[] args";
4: static String str2="main method with int[] args";
5:
6: public static void main(String[] args)
7: {
8: System.out.println(str1);
9: }
10:
11:public static void main(int[] args)
12:{
13:System.out.println(str2);
14:}
15:}
Select the one right answer.
A. Duplicate(复制) method main(),compilation error at line 6;
B. Duplicate method main(),compilation error at line 11;
C. Prints"main method with main String[]args".
D. Prints"main method with main int[]args".
正确答案:C

652. What is displayed when the following code is executed?
class parent{
private void method1(){
System.out.println("Parent's method1()");
}
public void method2(){
System.out.println("Parent's method2()");
method1();
}
}
class Child extends Parent{
Public void method1(){
System.out.println("Child's method1()");
}
public static void main(String args[]){
Parent p=new Child();
p.method2();
}
}
Select the one right avswer.
A. Compile-time error
B. Run-time error
C. Prints:Patent's method2() Parent's method1()
D. Prints:Patent's method2() Child's method1()
正确答案:C

653. What is displayed when the following code is executed?
class Paten{
void method1(){
System.out.println("Parent's method1()");
}
public void method2(){
System.out.println("Parent's method2()");
method1();
}
}
class Child extends Parent{
public void method1(){
System.out.println("Child's method1()");
}
public static void main(String args[]){
Parent p=new Child();
p.method2();
}
}
Select the one right answer.
A. Compile-time error
B. Run-time error
C. Prints:Parent's method2() Parent's method1()
D. Prints:Parent's method2() Child's method1()
正确答案:D

666. Examine the following class definition:
public class Test{
public static void test(){
print();
}
public static void print(){
System.out.println("Test");
}
public void print(){
System.out.println("Another Test");
}
}
What is the result of compiling this class:
Select the most appropriate answer.
A. A successful compilation.
B. A warning stating that there is a duplicated method.
C. An error stating that there is a duplicated method.
D. An error stating that the method test() will call one or other of the print() methods.

668. Carefully examine the following class:
public class Test{
public static void main(String args[]){
if (true){
Test t=new Test();
System.out.println("Done the test");
}
System.out. println("The end");
}
}
Select the most appropriate answer.
A. Prints out "Done the test"and nothing else.
B. Prints produces no output but terminates correctly.
C. Program does not terminates correctly.
D. The program will not compile.
E. The program generates a runtime exception.
F. The program prints out "The end"and mothing else.
G. The program prints out"Done the test"and "The end"

670.What a static inner class can access ? (selec one)
A.Any variables in the enclosing scope
B.Final variables in the enclosing scope
C.Static variables declared in side the method
D.上述答案都不对

679.Given the following code:
1.class Happy {
2.public static void main(String args[]){
3.public class Sad {
4.public void methodA() {
5.System.out.println("inside sad");
6.}
7.}
8.System.out.println("inside happy");
9.}
10.}
What will be the output?
A. compilation error at line no.3
B. compilation error at no.4
C. compilation error at line no.5
D.compilation succeeds but runtime exeption
E.clean compile and give the output "inside happy"

683. Given the extends Happy{
class Happy{
public int getLength(){
System.out.println("int version");
}
}
class Life extends Happy{
public long getLength(){
System.out.println("long version");
}
public static void main(String args[]){
Happy e=new Life();
e.getLength();
}
}
Which method gets executed?
A. int version
B. long version
C. compile time error
D. run time exception
E. clean compile but no output

Run()方法是什么的,他什么时候被调用

687. What appears in the standard output when you run the Dots class?
class Test impltements Runnable{
DotThread t;
public static void main(String[]args){
Test d=new Test();
d.t=new DotTgread();
}
public void init(){
t.start();
t=new DashThread().start();
}
}
class DotThread extends Thread{
public void run(){
for(int index=0;index<100;index++)
System.out.print(".");
}
}
class DashThread extends Thread{
public void run(){
for(int index=0;index<100;index++)
System.out.print("-");
}
}
Select the one right answer.
A. nothing
B. 100 dots(.)
C. 200 dots(.)
D. 100 dashes(-)
E. 100 dots(.)and 100 dashes(-)

694. Which statements are true about threads?
A. A thread can be created only by subclassing java.lang.Thread.
B. Invoking the suspend() method stops a thread so that it cannot be restarted.
C. The java interpreter's natural exit occurs when no non-daemon threads remain alive.
D. Uncoordinated changes to shared data by multiple threads may result in the data being read, or left, in an inconsistemt state.

696. Given the following class:
class Test {
public int startHere=1;
public int endHere=100;
public startic void main(String[] args){
new Test().go();
}
void go(){
//A
Thread 1=new Thread(a);
t.start();
}
}
What block of code can you replace at line A above so that this program will count from startHere to endHere?
Select all valid answers.
A. Runnable a = new Runnable(){
public void run(){
for (int i=starHere;i<=endHere;i++){
System.out.println(i);
}
}
};
B. implements Runnable{/
public void run(){
for(int i=starHere;i<=endHere;i++){
System.out.println(i);
}
}
};
C. Thread a=new Thread(){
public void run(){
for(int i=starHere;i<=endHere;i++)|
System.out.prinln(i);
}
}
};

704. Under what circumstances might you use the yield method of the Thread class?
A. To call from the currently running thread to allow another thread of the same or higher priority to run.
B. To call on a waiting thread to allow it to run
C. To allow a thread of higher priority to run
D. To call from the currently running thread with a parameter designating which thread should be allowed to run

705. Which of the following statements about threading are true?
A. You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements Runnable.
B. You can obtain a mutually exclusive lock on any object.
C. A thread can obtain a mutually exclusive lock on a synchronized method of an object.
D. Thread scheduling algorithms are platform dependent.

711. Select all the exceptions thrown by wait() method of an Object class, which you can replace in the place of xxx legally?
class Test implements Runnable{
public void run(){
System.out.println("Execrting run() method");
myTest();
}
public synchronized void myTest(){
try{
wait(-1000);
System.out.println("Execrting the myTest() method");
}XXX
}
}
public class MyTest{
public static void main(String args[]){
Test t=new Test();
Thread th=new Thread(t);
th.start();
}
}
Select the one right answer.
A. catch (InterruptedException ie){}
B. catch (IllegalArgumentException i1){}
C. catch (IllegalMonitorStateException i1){}
D. Only catch (InterruotedException e){} exception

718. The method resume() is responsible for resuming which thread's execution?
A. The thread which is stopped by calling method stop()
B. The thread which is stopped by calling method steep()
C. The thread which is stopped by calling method wait()
D. The thread which is stopped by calling method suspend()

712. There are 20 threads are waiting in the waiting pool with same priority. how can you invokes 15th thread from the wailing pool?
A. By calling resume() method
B. By calling interrupt() method
C. Calling call() method
D. By calling notify(15)method on the thread instance
E. None of the above

721. What happens when you try to compile and run the following application?
public class Test{
public static void main(String[] args){
new Test();
}
Test(){
Test alias1=this;
Test alias2=this;
synchronized(alias1){
try{
slias2.wait();
System.out.println("DONE WAITING");
}
Catch(InterruptedException e){
System.out.println("INTERR UPTED");
}
catch(Exception e){
System.out.println("OTHER EXCEPTION");
}
finally{
System.out.println("FINALLY");
}
}
System.out.println("ALL DONE");
}
}
Choose all correct options.
A. The application compiles but doesn't print anything.
B. The application compiles and print"DONE WAITING"
C. The application compiles and print "FINALLY"
D. The application compiles and print "ALL DONE"
E. The application compiles and print "INTERRUPTED"
正确答案: A

726. What is the result of compiling and executing the following Java class:
public class Test extends Thread{
public void run(){
System.out.println("In run");
suspend();
resume();
System.out.println("Leaving run");
}
public static void main(Syring args[]){
(new Test()).start();
}
}
Select the most appropriate answer.
A. Compilation will fail in the method main.
B. Compilation will fail in the method run.
C. A warning will be generated for method run.
D. The string" In run" will be printed to standard out.
E. Both strings will be printed tp standard out.
F. Nothing will happen.
正确答案: D

732. Which of the following statements are true?
A. all the threads created in a class will come to an end at the same tine.
B. you can stop a thread indefinitely if you wish to.
C. you can start a thread only by extending the Thread class.
D. multiple threads accessing same variable will lead to producing junk(not the exact word )data.
E. JVM exits after the main() thread is exited even if there might be some threads running.
正确答案: B D

SCJP考题15

分类: SCJP考题 2007-10-13 15:44 332人阅读 评论(0) 收藏 举报
22. A Java array is an ordered collection of three kinds of things. What are they?
Fill in the blank.
正确答案:primitives. object references, references to other arrays.

20. There are seven characters, at least one of which must be included to indicate a floating point literal. What are they?
Fill in the blank.
正确答案:'E','e', 'F', 'f', 'D', 'd', '.'

18. Show six different ways to express the decimal value 28 as an integral(完整的) literal.(文字的,照字面上的)
Fill in the blank.
正确答案:28,034, 0x1c, 0x1C, 0X1c, 0X1C

4. How you can use the escape notation u to set the variable c, declared as a char, to the Unicode character whose value is hex 0X30A0?
Fill in the blank.
正确答案:C=/u30a0;

10.What output is produced by the following program?
class Test{
public static void main(String args[]){
long size=10;
int[]array=new int[size];
size=20;
System.out.println(array.length);
}
}
Select the one right answer.
A. A compiler error.
B. A runtime error.
C. 10
D. 20
正确答案:A

28. What output is produced by the following program? Note that the main() method is not declared public.
class Test{
static void main(String args[]){
System.out.println("OK");
}
}
Select the one right answer.
A. A compiler error.
B. A runtime error.
C. OK
正确答案: C

29. What output is produced by the following program? Note that the main() method is not declared static.
class Test{
public void main(String args[]){
System.out.println("OK");
}
}
Select the one right answer.
A. A compiler error.
B. A runtime error.
C. OK
正确答案: B

33. True or false? In Java primitives(原始的) are passed by value and objects are passed by reference.
Fill in the blank.
正确答案: False

30. What is the purpose of the reference to the array of String references in the argument list of the main() method?
Fill in the blank.
正确答案: Thansfer of command-line arguments

500. Examine the following code which includes an inner class:
public final class Test implements A{
class Inner{
void test(){
if (!Test.this.flag);{
sample();
}
}
private boolean flag = false;
}
publi void sample(){
System.out.println("Sample");
}
public Test(){
(new Inner()).test();
}
public static void main(String args[]){
new Test();
}
}
What is the result?
A. Print out "Sample"
B. Program produces no output but terminates correctly.
C. Program does not terminate.
D. The program will not compile
正确答案: A

511. What appears in the standard output if the method named problem() in the code below throws an instance of class Exception when the method named trythis() is invoked?
public void trythis(){
try{
System.out.println("1");
problem();
}catch(RuntimeException x){
System.out.println("2");
return;
}catch(Exception x){
System.out.println("3");
return;
}finally{
System.out.println("4");
}
System.out.println("5");
}
Select all valid answers.
A. "1"
B. "2"
C. "3"
D. "4"
E. "5"
正确答案: A、C、D

513. Analyze the following code.
void looper(){
int x=0;
one:
while(x<10){
two: 非法标号
System.out.println(++x);
if(x > 3)
break two;
}
}
Select all valid answer.
A. This code compiles
B. This code does not compile
C. This code writes the number 0 to the standard output
D. The numbers 1 and 2 to the standard outout
E. The numbers 3 and to the standard outout
F. The numbers 4 to the standard outout
G. The numbers 5 through 9 to the standard outout
H. The numbers 10 to the standard outout
正确答案: B

520.What code placed after the comment For loop
would populate the elements of the array ia[] with values of the variable i?
public class Test{
public static void main(String argv[]){
Test 1=new Test();
1.amethod();
}
public void anethod(){
int ia[]=new int[4];
Start For loop
{
ia[i]=i;
System.out.println(ia[i]);
}
}
}
Select the one right answer.
A. for(int i=0;i<ia.length()-1;i++)
B. for(int i=0;i<ia.length();i++)
C. for(int i=1;i<4.i++)
D. for(int i=0;i<ia.length;i++)
正确答案: D

523. What will happen when you attempt to compile and run the following code?
public class Test{
static public long i=10;
public static void main(String argv[]){
switch(i){
default:
System.out.println("no value given");
case 1:
System.out.println("one");
case 10:
System.out.println("ten");
case 5):
System.out.println("five");
}
}
}
Select the one right answer.
A. Compile time error
B. Output of "ten"followed by "five"
C. Output of "ten"
D. Compilation and run time error because of location of default
正确答案: A

525. The thread run() method has the following code, what is the result when the thread runs?
try{
sleep(200); 不会扔出一个IOException
System.out.println("Printing from thread run()method");
}catch(IOException ie){}
Selet the one right answer.
A. Compile time error
B. Prints on the console Printing from thread run() method
C. At line 2 the thread will be stop running and resumes after 200 milliseconds and prints Printing from thread run() method
D. At line 2 the thread will be stop running and resumes exactly 200 milliseconds elapsed
正确答案: A

534. Given the incompleted method:
//line 1
{
success = connect();
if (success==-1){
throw new TimedOutException();
}
}
TimedOutException is not a RuntimeException. Which can complete the method of declaration when added at line 1?
A. public void method()
B. public void method() throws Exception
C. public void method() throws TimedOutException
D. public void method() throw TimedOutException
E. public throw TimedOutException viod method()
正确答案: B、C

542. Given the following code:
class Test{
public static void main(String args[]){
System.out.println(hai());
}
static int hai(){
try{
return 1;
}
catch(Exception e){
System.out.println("Exception");
}
finally{
System.out.println("Finally");
Return 2;
}
}
}
What will be the out put?
A. Compilation Error void main Can't return any value.
B. Prints Exception.
C. Prints Exception Finally.
D. Prints Finally and 1.
E. Prints Finally and 2.
正确答案:E

SCJP考题16

分类: SCJP考题 2007-10-13 15:46 474人阅读 评论(0) 收藏 举报
1. Wich three are valid declarations of a char?(choose three)
A char c1=064770;
B char c2=’face’;
C char c3=0Xbeef;
D char c4=/u0022;
E char c5=’/iface’;
F char c6=’/uface’;

A
C
F
2.what is the numerical range of a char ?(choose one)
A -128 to 127
B –(2^15)to(2^15)-1
C 0 to 32767
D platform dependent
E 0 to 65535

E

3. which three are valid declarations of a float?(choose three)
A float f1= -343;
B float f2=3.14;
C float f3=0X12345;
D float f4=42e7;
E float f5=2001.0D;
F float f6=2.81F;

A
C
F

4. which two of the following are legal declarations for nonnested (非嵌套)class and interface (choose two)
A final abstract class test{} final 和abstract 不能同时用在一个类中
B public static interface test{} 接口和类不能声明为static
C final public class test{}
D protected abstract class test{}
E protected interface test{} protected 不能标识类和接口
F abstract public class test{}

C
E
5.How many of the following are legal method declarations?
A protected abstract void m1();
B static final void m1(){}
C transient private native void m1(){} transient 只适用于变量声明,而不适用于类和方法声明。
D synchronized public final void m1(){}
E private native void m1();
F static final synchronized protected void m1(){}
A
B
D
E
F

6.which two are valid declarations within an interface?(choose two)
A public static short stop=23;
B protected short stop=23;
C transient short stop=23;
D final void madness(short stop);
E public Boolean madness(long bow);
F static char madness(double duty);
接口不能是protected, transient,final , static

A
E
7.Which three are valid method signatures in an interface?(choose three)
A private int get Area(); 接口方法必须是public
B public float getVol(float x);
C public void main(String[] args);
D public static void main(String[] args); 不能是static
E Boolean setFlag(Boolean [] test[]);
B
C
D

1.以如下方式构造一个二维数组

数组名称 = new 元素数据类型[元素数N][];
数组名称[0] = new 元素数据类型[元素个数];
… …
数组名称[N-1] = new 元素数据类型[元素个数];

例如: aArray = new String[2][];
aArray[0] = new String[3];
aArray[1] = new String[2];
2.一个二维数组如下:
int[][] aArray;
aArray = new int[1][];
aArray[0] = new int[3]; 则: aArray.length 得到 1
aArray[0].length 得到 3
3. 第一种方法
int[] max = {3,6,9};
String[][] s = “Hello”, “Java”}, {“北大方正”, “软件技术”, “网络”;
第二种方法:
int[] max;
max = new int[]{3,6,9};
4.数组的合法赋值
一.对于原始数据类型的数组,其元素在赋值时,既可以使用数组声明的那个类型的值,也可以使用那些可以自动转换成该类型的值
具体地说,如果声明了一个整型数值int类型的数组,则我们可以用,byte,char,short,int等类型的值来给这个数组赋值
二.对于非原始数据类型的数组,其元素在赋值时,既可以使用数组声明的那个类型的值,也可以使用那些与该类型具有IS-A关系的类型的值
具体地说,如果声明了一个A类型的数组,则我们可以用A的子类类型来给这个数组赋值,如果A是一个接口(interface)类型,则所有实现了这个接口的类都是合法的
三.对于原始数据类型的数组,在对其引用赋值时,只能使用相同类型的数组,而且维数也必须相同,但数组的长度可以是任意的
不要被自动类型转换所蒙骗,自动类型转换是在原始数据类型之间进行的,而数组尽管保存的是原始数据类型的量,但它本身是一个对象,不是原始数据类型,数组的引用是对一个对象的引用,也不是原始数据类型
四.对于非原始数据类型的数组,在对其引用进行赋值时,既可以使用相同类型的数组,也可以使用那些与该类型具有IS-A关系的类型的数组,只要它们的维数相同
具体地说,如果R是一个A类型数组的引用,则我们可以将A的子类类型的数组赋值给R,如果A是一个接口(interface)类型,则所有实现了这个接口的类型的数组都是合法的
5.修饰符分为访问修饰符和非访问修饰符
访问修饰符:public, protected ,private
非访问修饰符:strictfp ,final, abstract
6.
一.对Java的类来说,只有public和默认的访问控制是有意义的,也就是说,在类的定义前面,或者使用public的访问控制,或者什么也不写,使用默认的访问控制

7.最终:final
final用于修饰方法,则该方法不能在子类中被重写
final用于修饰变量,则该变量表示一个常量,只能在初始化时被赋值,不能再在其它地方被赋值
final还可以用于修饰方法的参数,指出这个参数在方法体中不能被赋值修改

同步方法:synchronized
synchronized用于修饰方法,表明该方法一次只能被一个线程所访问
synchronized不能与abstract一起使用,也不能用于变量和类,但它可以和public,protected,private,final等一起使用

本地方法:native
native用于修饰方法,表明该方法是用其它与平台相关的语言设计的,比如C
native不能与abstract一起使用,也不能用于变量和类

strictfp
strictfp用于修饰方法,表明该方法中的浮点操作遵守IEEE754标准
strictfp可以用来修饰类和非抽象方法
strictfp不能与abstract一起使用,也不能用于变量

瞬态变量:transient
在对包含用transient修饰的实例变量的对象作串行化处理时应该跳过这个变量

挥发变量:volatile通JVM,访问该变量的线程要使其私有拷贝与内存中的主拷贝一致,在考试中,对上述两个修饰符的要求基本上就是:它们是保留关键字,只能应用于实例变量

8.abstract不能与final一起使用
abstract不能与private一起使用
abstract不能与synchronized一起使用
abstract不能与native一起使用
abstract不能与strictfp一起使用
abstract不能与static一起使用
最后:abstract不能用于成员变量

9.在interface中定义的变量都是final的,虽然它前面也许什么都没写,实际上所有接口变量都是
public static final的

10.局部变量不可以使用任何访问修饰符
局部变量也不可以使用除final以外的任何其它非访问修饰符
任何在局部变量上使用不法修饰符的代码都会得到一个编译错误

11.instanceof比较其左边的对象是不是右边的类型
例如: a instanceof String;
测试对象a是不是一个字符串类型的对象

实际上,左边的对象如果与右边的类型具有is-a的关系时,都将返回true

12.断言语句非常简单,有两种格式:
1. assert(布尔表达式);
2. assert(布尔表达式):信息字符串

如果布尔表达式为false,就产生一个AssertionError,第二种情况时,那个信息字符串会被放到栈里
1. 在编译时使用参数 –source1.4
2. 在运行时使用参数 –ea 开启断言
3. 在运行时使用参数 –da 关闭断言

javac –source 1.4 Hello.java
java –ea Hello
java –da Hello

13. IS-A的关系来自于继承
子类IS-A父类,子类“是”父类
HAS-A的关系来自于对象之间的调用
一个类A HAS-A 另一个类B,是指在类A中有对B的对象的调用
14.
在重写中,所谓子类中方法的访问控制不能比父类中方法的访问控制范围窄是指:
Ø 一个package方法可以被重写为package、protected和public的
Ø 一个protected方法可以被重写为protected和public的
Ø 一个public方法只可以被重写为public的

15.
1.用this(…)调用重载的构造函数
2.用super(…)调用父类的构造函数
3.this(…)或者super(…)调用必须是构造函数的第一条语句
4.子类的构造函数会自动调用父类无参数的构造函数
8. 抽象类可以有构造函数,但只能用来被子类的构造函数调用
9. 接口/interface没有构造函数
10. 构造函数可以有任意的访问控制符,甚至是private
11. 在一个构造函数里面,可以有this(…),也可以有super(…),但不能同时有都有

SCJP考试常用的英语

分类: SCJP考题 2007-10-13 15:47 304人阅读 评论(0) 收藏 举报
Fundamentals(基本原则) Section(部分,节) blueprint(蓝图,设计图)
Particular特殊的 category 类别 concrete realization 具体的实现
Reference 涉及,引用 represents(描述) concerning 关于
non-negative(正的,非负的)representation(表示法)circumstances(环境)
uniquely(独特的,无一的)vertical(垂直的)Indicated(指出的) position
anonymous class 匿名类

Suspend 挂起
resume 恢复
Snapshot 快照
exceptional condition 异常情形
Dynamic 动态的 动力学的,动力的
Java interpreter(解释程序)
informs(通知)
reclaims(收回)
candidate(侯选人)
Note the placeholder comma in the boldface portion.)注意黑字体的一部分(占位符逗号
integral(完整的) literal.(文字)
represent(表现)
code snippet 代码片断
normally 正常地
associates with(与—-联系)
applicable(可适用的)
circumstances(环境)
rectangular(矩形的) grid(格子)
rectangles(长方形)
blueprint(蓝图,设计图)
Fundamentals(基本原则)
instantiated(例示)
represents(描述)
representation(表示法)
uniquely(独特的,无一的) identify(识别,鉴定)
triggered(触发的)
Orientation(方向,方位)
Indicated(指出的)position
candidate(侯选人)
optimizations(最优化)
gracefully(温文地)
guaranteed(保证,担保)
issue(发布,发出)
enforced(强迫)
reverse 倒转

最新java考题测验

http://cert.xinfengit.com/201011/068497.html
 第一部分:选择题
  question no: 1
  1、public class test
  public static void main
  }
  please write the output result :
  question no:2
  1. public class test
  6. public static void main
  13. } 考试用书
  14. }
  what is the result?
  a. abdcbdcb
  b. abcdabcd
  c. compilation fails.
  d. an exception is thrown at runtime。
  question no: 7
  which of the following statements regarding the lifecycle of a session bean are correct?
  1. java.lang.illegalstateexception is thrown if sessioncontext.getejbobject is invoked when a stateful session bean instance is passivated.
  2. sessioncontext.getrollbackonly does not throw an exception when a session bean with bean-managed transaction demarcation is activated.
  3. an exception is not thrown when sessioncontext.getusertransaction is called in the afterbegin method of a bean with container-managed transactions.
  4. jndi access to java:comp/env is permitted in all the sessionsynchronization methods of a stateful session bean with container-managed transaction demarcation.
  5. accessing resource managers in the sessionsynchronization.afterbegin method of a stateful session bean with bean-managed transaction does not throw an exception.
  第二部分:概念题
  1. 描述struts体系结构?对应各个部分的开发工作主要包括哪些?
  2. xml包括哪些解释技术,区别是什么?
  3. jsp有哪些内置对象和动作?它们的作用分别是什么?
  4、sql问答题
  0select * from table
  和
  0select * from table
  where name like ’%%’ and addr like ’%%’
  and
  的检索结果为何不同?
  5、sql问答题
  表结构:
  1、 表名:g_cardapply
  字段: 源:中华考试网
  g_applyno varchar 8;申请单号(关键字)
  g_applydate bigint 8;
申请日期
  g_state varchar 2;申请状态
  2、 表名:g_cardapplydetail
  字段:
  g_applyno varchar 8;
申请单号(关键字)
  g_name varchar 30;申请人姓名
  g_idcard varchar 18;
申请人身份证号
  g_state varchar 2;//申请状态
  其中,两个表的关联字段为申请单号。
  题目:
  1、 查询身份证号码为440401430103082的申请日期
  2、 查询同一个身份证号码有两条以上记录的身份证号码及记录个数
  3、 将身份证号码为440401430103082的记录在两个表中的申请状态均改为07
  4、 删除g_cardapplydetail表中所有姓李的记录

字符串考试

http://www.oschina.net/code/snippet_5189_3329

String a = "abc";
String b = "abc";
String ab = "ab";
String c = ab + "c";
String d = "ab"+"c";

System.out.println( a==b );
System.out.println( a==c );
System.out.println( a==d );