1、Java试题及答案英文版doc1 Which two dem on strate an uis a” relati on ship? (Choose Two)A.public interface Person public class Employee exte nds Pers on B.public interface Shape public class Employee extends Sha pe C.public in terface Color public class Employee extends Color D.public class Species public cl
2、ass Animalprivate Species species;E.in terface Comp orient Class Container implements Component (Private Component children;Answer:de2.Given:1.package foo;2.2.public class Outer (3.public static class Inn er (4.)5.)Which statement is true?A.An instance of the Inner class can be constructed with “new
3、 Outernner ()”B.An instance of the inner class cannot be constructed outside of package fooC.An instance of the inner class can only be constructed from within the outer classD.From within the package bar, an instanee of the inner class can be constructed with “new inner()nAnswer:c3. Exhibit:1public
4、 class enclosinggone2public class insideone34public class inertest5public static void main (Stringf args)6enclosingone eo = new enclosingone();7/insert code here8Which state me nt at li ne 7 con structs an instance of the inner class?A.InsideOne ei = eo.new lnsideOne();B.B. EonsideOne ei = eo.new In
5、sideOne();C InsideOne ei = EnclosingOne.new InsideOne();D.EnclosingOne InsideOne ei = eo.new lnsideOne();An swer:aC.4.D.1) class SuperE.2) public float getNum()return 3.Of;F3) G.4)H.5) public class Sub extends SuperI.6)J 7) K. which method, placed at line 6, will cause a compiler error?L.A. public f
6、loat getNum()return 4.Of;M. B. public void getNum()N. C. public void getNum(double d)O. D. public double getNum(float d)return 4.0d;Answer:B5.1)public class Foo2)public static void main(String args)3)tryreturn;4)finally! System.out.println(Finally,);5)6)what is the result?A.The program runs and prin
7、ts nothing.B.The program runs and prints “Finally”.C.The code compiles, but an exceptio n is thrown at run time D.The code will not compile because the catch block is missing.Answer:b6/point Xpublic class Foopublic static void main(String args)PrintWriter out=new PrintWriter(newjava.io.OutputStreamW
8、riter(System.out),true);out.println(,HelloH);which statement at point X on line 1 allows this code to compile and run?A.import java.io.PrintWriter B.inelude java.io.PrintwriterC.import java.io.OutputStreamWriter D.include java.io.OutputStreamWriterE.No state me nt is n eededAnswer:a6.which three are
9、 valid declaraction of a float?A.float foo=-1;B.float foo=1.0;C.float foo=42e1;D.float foo=2.02f;E.float foo=3.03d;F.float foo=0x0123;An swer:adf8.int index=1;int foo=new int3;int bar=fooindex;int baz=bar+index;what is the result?A.baz has a value of 0B.baz has value of 1C.baz has value of 2D.an exc
10、eption is thrownE.the code will not compileAnswer:b9.1)int i=1,j=10;2)do3)if(i+-j) continue; 192837464)while(ij)continue;卜; while(+iv6);what are the vale of i and j?A.i=6,j=5B.i=5,j=5C.i=6,j=4D.i=5,j=6E.i=6,j=6Answer: A20byte arrayl ,array2byte array3byte array4if each has been initialized, which st
11、atement will cause a compile error?A.array2 = arrayl;B.array2 = array3;C.array2 = array4;D.both A and BE.both A and CF.both B and CAnswer: a21.which four types of objects can be thrown use ”throws”?A.ErrorB.EventC.ObjectD.Excpti onE.ThrowableF.Run timeExcepti onAnswer: A,D,E, F22.1)public class Test
12、2)public static void main(String args)3)unsigned byte b=0;4)b-;5)5)6)what is the value of b at line 5?A.-1 B.255 C.127 D.compile fail E.compile succeeded but run errorAnswer: d23.public class ExceptionTestclass TestException extends Exceptionpublic void runTest() throws TestExceptionpublic void test
13、() /* point x */ run Test();At point x, which code can be add on to make the code compile?A.throws ExceptionB.catch (Exception e)C.throws RuntimeExceptionD.catch (TestException e)E.no code is necessaryAnswer: A24String foo=”blue”;boolean bar=new boolean1;if(barO)foo=HgreenH;what is the value of foo?
14、A.” B.null C.blue D.gree nAnswer: C25.which two are equivale nt?A.3/2B.32C.3*4D.32E.3*2A2F.32Answer: c,d26.int index=1;String test=new String3;String foo=testindex;what is the result of foo?A.foo has the value “ ”B.foo has the value nullC.an exception is thrownD.the code will not compileAn swer: b27
15、.which two are true?A.static inner class requires a static initializerB.A static inner class requires an instanee of the enclosing classC.A static inner class has no ref ere nee to an in stance of the enclosi ng classD.A static inner class has accesss to the nonstatic member of the other classE.stat
16、ic members of a static inner class can be ref ere need using the class name of the static inner classAnswer: c,e28.You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access modifier that will accomplish this objective?A.PublicB.PrivateC.Protec
17、tedD.TransientE.No access modifier is qualifiedAn swer:c29.Given:1.abstract class abstrctlt 2.abstract float getFloat ();3.)4.public class AbstractTest extends Abstractly5.private float f1= 1.0f;6.private float getFloat () return f1:7What is the result?A.Compilation is successful.B.An error on line 6 causes a run time failure.C.An error at line 6 causes compilation to fail.D.An error at line 2 causes compilation to fail.An s
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1