Java classic test questions (1)

xiaoxiao2021-03-06  65

Simulate Test of Scjp for Java2 Platform (Only for Training)

1. 1) Public class returnit {2) Returntype methoda (byte x, double y) {3) return (short) x / y * 2; 4)} 5)} What is valid Returntype for Methoda in line 2? Answer: Double

2. 1) Class Super {2) Public float getnum () {RETURN 3.0F;} 3)} 4) 5) Public class sub extends super {6) 7)} Which Method, Placed At line 6, Will Cause A Compiler ERROR? A. Public float getnum () {return 4.0f;} B. Public void getnum () {} C. Public void getnum (double d) {} ​​D. public double getnum (float d) {Return 4.0d;} Answer: B

3. Public class iftest {public static void main (string args []) {int x = 3; int y = 1; if (x = y) system.out.println ("not equal"); Else System.out. Println ("Equal");}} What is the result? Answer: Compile Error

4. Public class foo {public static void main (string args []) {Try {RETURN;} finally {system.out.println ("finally");}}}}}} What is the result? A. Print Out Nothing B. Print Out "Finally" C. Compile Error Answer: B

5. Public class test {public static string output = ""; public static void foo (int i) {try {if (i == 1) {throw new exception ();} Output = "1";} catch Exception e) {OUTPUT = "2"; return;} finally {OUTPUT = "3";} Output = "4";} public static void main (string args []) {foo (0); foo (1); 24)}} What is the value of output at line 24?

Answer: 13423

6. Public class ifelse {public static void main (String args []) {if (ODD (5)) System.out.Println ("ODD"); Else System.Out.println ("Even");} public static INT ODD (INT X) {RETURN X% 2;}} What is output? Answer: Compile Error

7. Class ExceptionTest {public static void main (string args []) {try {methoda ();} catch (ioException e) {system.out.println ("cauption e) {system. out.println ( "caught Exception");}}} If methodA () throws a IOException, what is the result Answer: caught IOException exception can catch once only if change the sequence of catch catch (IOException e) can not execute? And Compiler Will Report Rongyu Error

8. INT i = 1, j = 10; do {IF (i > - j) Continue;} while (i <5); after exec execution, What are the value for i and j? A. i = 6 j = 5 bbi = 5 j = 5 C. i = 6 J = 4 D. i = 5 J = 6 E. i = 6 J = 6 Answer: D

9. 1) Public class x {2) public object m () {3) Object o = new float (3.14f); 4) Object [] OA = New Object [1]; 5) OA [0] = O; 6) o = null; 7) OA [0] = null; system.out.println (OA [0]); 9)} 10)} Which line is the earliest point the object a refered is definitely elibile to be garbage collectel A.AFTER LINE 4 B. After Line 5 C.AFTER LINE 6 D.AFTER LINE 7 E.AFTER LINE 9 (That IS, AS THE Method Returns) Answer: D

10. 1) Interface foo {2) int K = 0; 3)} 4) Public class tests foo {5) Public static void main (string args []) {6) INT i; 7) Test test = new test (); 8) i = Test.k; 9) i = test.k; 10) i = foo.k; 11)} 12)} What is the result? Answer: compile successssed and i = 0

11. What is Reserved Words in Java? A. Run B. Default C. Implement D. Import Answer: B, D12. Public Class Test {public static void main (string "args) {string foo = args [1]; SRING BAR = Args [2]; String Baz = args [3];}} Java Test Red Green Blue What Is The Value Of Baz? A. Baz Has Value of "B. Baz Has Value of Null C. Baz Has Value Of "Red" D. Baz Has Value of "Blue" E. Baz Has Value of "Green" F. The code does Not Compile G. The Program Throw An Exception Answer: g

13. Int index = 1; int foo [] = new int [3]; int bar = foo [index]; int baz = bar index; What is the result? A. Baz Has A Value of 0 B. Baz HAS Value of 1 C. Baz Has Value of 2 D. An Exception Is Thrown E. The Code Will NOT Compile Answer: B

14. Which THREE VALID DECLARACTION OF A FLOAT? A. float foo = -1; B. float foo = 1.0; C. float foo = 42E1; D. float foo = 2.02F; E. float foo = 3.03d; f Float foo = 0x0123; Answer: a, d, f

15. Public class foo {public static void main (string args []) {string s; system.out.println ("s =" s);}} What is the result? Answer: compile error

16. 1) Public class test {2) public static void main (string args []) {3) I = oxfffffff1; 4) INT j = ~ i; 5) 6)} 7)} Which is Decimal Value Of J AT LINE 5? A. 0 B.1 C.14 D.-15 E. Compile Error At line 3 F. Compile Error At line 4 Answer: C

17. float f = 4.2f; float g = new float (4.2f); double d = new double (4.2); Which Are True? A. f == g B. g == g C. D == f D D. Equals (f) E D. Equals (G) F. G.Equals (4.2); Answer: B, E

18. Public class test {public static void add3 (Integer i) {3) int val = I.intValue (); val = 3; i = new integer (val);} public static void main (string args [] { Integer i = new integer (0); add3 (i); system.out.println (I.intValue ());}} What is the result? A. Compile fail B.Print Out "0" C.Print Out " 3 "D.Compile Succeded But Exception At line 3 Answer: b19. Public class test {public static void main (string [] args) {system.out.println (6 ^ 3);}} What is output? Answer: 5 ^ is yi huo

20. Public class test {public static void stringReplace (string text) {text = text.replace ('j', 'l');} public static void bufferreplace (StringBuffer text) {text = text.append ("c") ;} public static void main (String args []) {String textString = new String ( "java"); StringBuffer textBuffer = new StringBuffer ( "java"); StringReplace (textString); bufferReplace (textBuffer); System.out.println (TextString TextBuffer;}} What is the output? Answer: Javajavac

21. Public Class Constover {Public Constover (INT X, INT Y, INT Z) {}} Which two overload the constover conditionor? A.constover () {} B.Protected int covers () {} // not overload, but NO A Error C.Private Constover (int Z, int y, byte x) {} d.public void constover (byte x, byte y, byte z) {} E.PUBLIC OBJECT Conntover ) {} Answer: a, c

22. Public class methodover {public void setvar (int A, int b, float c) {}} Which overload the setvar? A.private void setvar (int A, float c, int b) {} B.Protace Void setvar (B.Protace C, INT B) INT A, INT B, FLOAT C) {} C.Public int setvar (int A, float c, int b) {return a;} d.public int setvar (int A, float c) {Return A;} answer: . A, C, D23 class EnclosingOne {public class InsideOne {}} public class InnerTest {public static void main (String args []) {EnclosingOne eo = new EnclosingOne (); // insert code here}} A.InsideOne ei = EO.NEW INSIDEONE (); c.insideone ei = ENCLOSINGOGONE.NEW INSIDEODEOGODIDEONE (); E.EnclosingOne.InSideone EI = EO.NEW INSIDEONE (); Answer: E

24. What is "is a" relation A.public interface Color {} public class Shape {private Color color;}? B.interface Component {} class Container implements Component {private Component [] children;} C.public class Species { } Public class animal {private species species;} d.interface a {} interface c imports a, b {} // syntex error Answer: B Keyword Implements, Entes

25. 1) Package foo; 2) 3) Public class {4) public static class inner {5)} 6)} Which is true to instantiated inner class inside @ A. New Outer.inner () B. New Inner () Answer: b if out of outerclass a is correct

26. Class Baseclass {private float x = 1.0f; private float getvar () {return x;}} class subclass extends baseclass {private float x = 2.0f; // INSERT code} What are True to override getvar ()? A .float getvar () {c.Public float getvar () {d.Protected float getvar () {E.PUBLIC FLOAT GETI (FLOAT F) {Answer: A, B, D27. Public Class Sychtest {private int x; private int y; public void setx (int i) {x = i;} public void sety (int i) {y = i;} public synchronized void setxy (INT i) {setx (i); Sety (i);} public synchronized boolean check () {RETURN X! = Y;}} Under Which Conditions Will Check () RETURN TRUE WHEN CALED From A Different Class? A.Check () Can Never Return True. B.Check () can return true when setXY is callled by multiple threads. C.check () can return true when multiple threads call setX and setY separately. D.check () can only return true if SychTest is changed allow x and y to be setSeparately. Answer: C

28. 1) Public class x imports Runnable {2) Private int x; 3) Private int y; 4) Public static void main (string [] args) {5) x That = new x (); 6) (New Thread ()). START (); 7). START ();} 9) Public synchronized void Run () {10) for (;;) {11) x ; 12) y ; 13 ) System.out.println ("x =" x ", y =" y); 14)} 15)} 16)} What is the result? A.Compile Error At line 6 B.The Program Prints Pairs of Values ​​for x and y That Are Always The Same on The Same Time Answer: B

29. Class A Implements Runnable {INT I; Public Void Run () {Try {Thread.sleep (5000); i = 10;} Catch (InterruptException E) {}}} public static void main (string [] args) { Try {a a = new a (); thread t = new thread (a); t.start (); 17) INT j = ai; 19)} Catch (Exception E) {}}} What be added at line Line 17, ENSURE J = 10 AT line 19? A. a.wait (); b. t.wait (); c. T.JOIN (); DTYIELD (); etNotify (); f. A.Notify ); GtInterrupt (); Answer: C30. Given an ActionEvent, How to indentify the Affected Component? A.getTarget (); B.GetClass (); c.getsource (); // public object d.getActionCommand (); Answer: C

31. Import java.awt. *; Public class x extends frame {public static void main (string [] args) {x = new x (); x.pack (); x.setvisible (TRUE);} PUBLIC X () {SetLayout (New GridLayout (2, 2)); PANEL P1 = New Panel (); add (p1); button b1 = new button ("one"); p1.add (b1); panel p2 = new Panel (); Add (p2); Button B2 = New Button ("Two"); P2.Add (b2); Button B3 = New Button ("Three"); P2.Add (b3); button b4 = New Button "Four"); add (b4);}} When the frame is resize, a.all change Height B.All Change Width C.Button "One" Change Height D.Button "THREE" Change Width F.Button "Four" Change Height and Width Answer: f

32. 1) Public class x {2) public static void main (string [] args) {3) String foo = "abcde"; 4) foo.substring (3); 5) foo.concat ("xyz"); 6)} 7)} What is the value of foo at line 6? Answer: abcde33. How to calculate Cosine 42 Degree? A.double d = math.cos (42); B.DOUBLE D = Math.cosine (42) C. Double D = Math.cos (Math.ToraDians (42)); D. Double D = Math.cos (Math.todegrees (42)); E.DOUBLE D = Math.ToraDious (42); Answer: C

34. Public class test {public static void main (string [] args) {stringbuffer a = new stringbuffer ("a"); StringBuffer B = New StringBuffer ("b"); Operate (A, B); System.out. PINTLN (A "," B);} public static void Operate (StringBuffer X, StringBuffer Y) {x.append (y); y = x;}} What is the output? Answer: A, B

35. 1) Public class test {2) public static void main (string [] args) {3) Class foo {4) public int i = 3; 5)} 6) Object o = (Object) New foo (); 7) Foo foo = (foo) O; system.out.println (foo.i); 9)} 10)} What is result? A.Compile Error At line 6 B.Compile Error At line 7 C.Print Out 3 Answer: C

36. Public class foobar {public static void main (string [] args) {INT i = 0, j = 5; 4) TP: for (;; i ) {for (;; - j) if (i> j Break TP;} system.out.println ("i =" i ", j =" j);}} What is the result? Ai = 1, j = -1 B. i = 0, J = - 1 Ci = 1, J = 4 di = 0, j = 4 E.Compile Error At line 4 Answer: B

37. Public class foo {public static void main (string [] args) {try or {system.Exit (0);} finally {system.out.println ("firmly");}}} What is the result? A. Print Out Nothing B.Print Out "Finally" Answer: a system.exit (0) HAS EXIT38. Which four type "throws"? A. Error B.Event C.Object D.Excption E.THROWABLE F.RuntimeException Answer: a, d, e, f

39.1) Public class test {2) public static void main (string [] args) {3) unsigned byte b = 0; 4) b -; 5) 6)} 7)} What is the value of b at LINE 5? A.-1 B.255 C.127 D.Compile Fail E.Compile successmededed but Run Error Answer: D

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

41. String foo = "blue"; boolean [] bar = new boolean [1]; if (bar [0]) {foo = "green";} What is the value of foo? A. "" B. Null C .boe d.green answer: c

42. Public class x {public static void main (string args []) {Object O1 = New Object (); Object O2 = O1; IF (O1.Equals (O2)) {system.out.prinln ("Equal") }}} What is result? Answer: Equal

43. Which Two Are Equivalent? A. 3/2 B. 3 <2 C. 3 * 4 D. 3 << 2 E. 3 * 2 ^ 2 F. 3 <<< 2 Answer: C, D

44. INDEX = 1; string [] test = new string [3]; string foo = test [index]; what is the result of foo? A. "" B. Null C.THROW A Exception D.Not Compile Answer : B

45. Public class test {static void leftshift (int i, int j) {i << = j;} public static void main (string args []) {INT i = 4, j = 2; Leftshift (i, j) System.out.Println (i);}} What is the result? Answer: 4

46. ​​Public class x {private static int A; public static void main (string [] args) {modify (a); system.out.println (a);} public static void modify (int a) {a ;}} What is the result? Answer: 0

47. Public class test {private static int j = 0; public static boolean methodb (int K) {J = K; return true;} public static void methoda (int i) {boolean b; b = i> 10 & methodb (1) ; B = I> 10 && methodb (2);} public static void main (string args) {Methoda (0); 17)}} What is the value of j at line 17? Answer: 1

48. Class a {public string toString () {return "4";}} class b extends a {public string toString () {Return Super.toString () "3";}} public class test {public static void main (String args) {b = new b (); system.out.println (b.tostring ());}} What is the result? Answer: 43

49. Class A Implements Runnable {Public INT i = 1; Public Void Run () {this.i = 10;}} Public Class Test {Public Static Void Main (String Args) {a a = new a (); 11) New thread (a) .start (); int J = ai; 13)}} What is the value of j at line 13? A. 1 B. 10 C. The value of j cannot be determined D. An Error AT LINE 11 Cause CompiLATION to Fail Answer: C

50. public class SyncTest {public static void main (String [] args) {final StringBuffer s1 = new StirngBuffer (); final StringBuffer s2 = new StirngBuffer (); new Thread () {public void run () {Synchronized (s1) {S1.Append ("a"); synchronized (s2) {s2.append ("b"); system.out.print (S1); System.out.print (S2);}}}} .start () New thread () {public void Run () {synchronized (s2) {s2.append ("c"); synchronized (s1) {s1.append ("d"); system.out.print (S2); System.Print .out.print (S1);}}}} .start (); Class test {public static void main (string "args) {string foo =" blue "; string bar = foo; foo =" green "; system.out.println (bar);}} What is the result? Answer: Blu e

52. Which interface hashtable imports? A. java.util.map B. java.util.list C. java.util.hashable D. java.util.collection answer: a

53. which two are true? A. static inner class requires a static initializer B. A static inner class requires an instance of the enclosing class C. A static inner class has no reference to an instance of the enclosing class D. A static inner Class Has Access to the Non-Static Member of the Other Class E. Static Members of A Static Inner Class Can Be Reference Using The Class Name of The Static Inner Class Answer: C, E

54. which two are true? A. An anonymous inner class can be declared inside of a method B. An anonymous inner class constructor can take arguments in some situations C. An anonymous inner class that is a direct subclass of Object can implements multiple interface D. Even if a class Super does not implement any interfaces, it is still possible to define an anonymous inner class that is an immediate subclass of Super that implements a single interface E. Even if a class Super does not implement any interfaces, it is . still possible to define an anonymous inner class that is an immediate subclass of Super that implements multipe interface Answer: A, D55 class A {public int getNumber (int a) {return a 1;}} class B extends A {public int GetNumber (int A, char c) {RETURN A 2;} public static void main (string [] args) {b = new b (); 14) System.out.println (B.GetNumber (0)); }} What is the resul T? A. Compilation Succeeds and 1 Is Printed B. Compilationed Succeeds and 2 Is Printed C. An Error At Line 8 Cause Compilation To Fail D. An Error At Line 14 Cause Compilation To Fail Answer: A

56. Import java.awt. *; Public class x extends frame {public static void main (string [] args) {x = new x (); x.pack (); x.setVisible (TRUE);} public x () {SetLayout (New borderLayout (); panel p = new panel (); add (p, borderlayout.north); button b = new button ("north"); p.Add (b); button b1 = new Button ("South"); add (b1, borderlayout.south);} Which two area True? A. The Button Labled "North" and "South" Will Have The Same Width B. The Button Labled "North" and "South "will have the same height C. The height of the button labeled" North "can vary if the Frame is resized D. The height of the button labeled" South "can vary if the Frame is resized E. The width of the button labeled "North" is constant even if the Frame is resized F. The width of the button labeled "South" is constant even if the Frame is resized Answer: B, E57 which two interfaces provide the capability to store objects using a key-value. Pair? a. java.util. Map B. Java.util.set C. Java.util.list D. Java.util.SortedSet E. Java.util.SortedMap F. Java.util.Collection Answer: A, E

58. Which two declareetions prevent the overriding of a method? A. Final void methoda () {} B. Void final methoda () {} C. static void methoda ()} D. static final void methoda () {} e Final abstract void methoda () {} answer: a, d

59. which two are true public class OuterClass {private double d1 = 1.0; // inser code here}? A. static class InnerOne {public double methoda () {return d1;} B. static class InnerOne {static double methoda () {return d1;} C. private class InnerOne {public double methoda () {return d1;} D. protected class InnerOne {static double methoda () {return d1;} E. public abstract class InnerOne {public abstract double methoda () ; Answer:. C, E60 You want a class to have access to members of another class in the same package which is the most restrictive access modifier that will accomplish this objective A. public B. private C. protected D. transient E.? NO acess modifier is required answer: e

61. Which Two Statements Declare ARRAY CAPABLE OF 10 INTS? A. Int [] foo; B. Int foo []; C. Int foo [10]; D. Object [] foo; E. Object foo [10]; Answer: a, b

62. Public class switchtest {public static void main (string [] args) {3) System.out.println ("Value =" Switchit (4));} public static int switchit (int x) {INT J = 1 Switch (x) {case 1: j ; case 2: j ; case 3: j ; case 4: j ; case 5: j ; default: j ;} returnj x;}} What is the output from line 3 A. Value = 3 B. Value = 4 C. Value = 5 D. Value = 6 E. Value = 7 F. Value = 8 Answer: f

63. which will declare a method that is available to all members of the same package and can be referenced without an instance of the class A. abstract public void methoda ();? B. public abstract double methoda (); C. static void methoda (double d1) {} D. public native double methoda () {} E. protected void methoda (double d1) {} Answer:. C64 1) public class SuperClass {2) class SubClassA extends SuperClass {} 3) class SubClassB Extends superclass {} 4) PUBLIC VOID TEST (SUBCLASSA FOO) {5) Superclass Bar = foo; 6)} 7)} Which Statement IS TRUE About The Assignment in line 5? A. The Assignment in line 5 Is Illegal B. The Assignment in line 5 IS Legal, But throw a classcastexception C. Legal and will always Executes WITHOUT THROW AN Exception Answer: C

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

66. Public class x imports Runnable {public static void main (string [] args) {3) // insert code} public void run () {int x = 0, y = 0; for (;;) {x ; y System.out.println ("x =" x ", y =" y);}}} Which Codes Areadded to line 3 to cause run () to be evecuted? A. x x = new x () X.Run (); B. x x = new x (); new thread (x) .Run (); C. x = new x (); new thread (x) .start (); D. Thread T = New Thread (x) .Run (); E. Thread T = New Thread (x) .start (); Answer: c (a) Because Run is not static67. Which gets the name of the parent Directory of File File.txt "? a. String name = file.getParentName (" file.txt "); b. String name = (New file (" file.txt ")). getParent (); c. string name = (New file) ("file.txt"))). getParentName (); D. String name = (New file ("file.txt")). getParentFile (); E. DireTory Dir = (New File ("file.txt")) .getparentdir (); string name = dir.getname (); answer: b

68. The file "file.txt" exists on the file system and contacts ascii text. Try (file.txt "); OutputStream out = new fileoutputstream (f);} catch (ooException e) { } A. The code does not compile B. The code Runs and no change is master to the file c. The code runs and sets the length of the file to 0 d. an Exception is thrown because the file is not closed E. THE Code Runs and deletes the file from the file system answer: c

69. Class super {public INT i = 0; public super (string text) {i = 1;}} public class sub extends super {public sub (string text) {i = 2;} public static void main (string args ]) {SUB SUB = New Sub ("Hello"); System.out.Println (Sub.i);}} What is the result? A. Compile Will Fail B. Compile Success And Print "0" C. Compile SUCCESS And print "1" D. Compile Success and print "2" Answer: a public class sub extends super {public sub (string text) {Super (), this must be the first line.}; 70. Import java.io. IOException; public class ExceptionTest {public static void main (String args []) {try {methodA ();} catch (IOException e) {System.out.println ( "Caught Exception");}} public void methodA () { Throw new ooException ();}} What is the result? a.the code will not compile b.the output is caught exception C.THE OUTPUT IS CAUGHT IOEXCEPTION D.THE PROGRAM EXECUTES NORMALLY WITHOUT Printing a Message Answer: a

71. You are assigned the task of building a Panel containing a TextArea at the top, a Labbel directly bellow it, and a Button directly bellow the Label. If the three components added directly to the Panel. Which layout manager can the Panel use to Ensure That TEXTAREA ABSORBS All of the Free Vertical Space WHEN THE PANEL IS RESIZED? A.GridLayout B.CardLayout C.FlowLayout D.BorderLayout E.GridbagLayout Answer: E

72. You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be access in nature order, which interace provides that capability? A. java.uil.Map B.java.util.Set C.java .util.List D.java.util.SortedSet E.java.util.SortedMap F.java.util.Collection Answer:. B73 which two can not directly cause a thread to stop executing A.calling the yield method B.calling the? Wait Method on an Object C.calling the notify method on an Object D.calling The NotifyAll Method on an Object E.CALLING THE Start Method on Another Thread Object Answer: a, e

74. 1) Public class foo imports Runnable {2) Public void Run (thread t) {system.out.println ("running");} public static void main (String [] args) {new three (new foo () ) .Start ();}} What is the result? A. JXTTION IS Thrown B.The Program EXITS WITHOUT Printing Anything C. Orship To Fail D. An Error At Line 2 Causes Complication To Fail E "Running" IS pinted and the program exits Answer: D

75. Which Method in The Thread class is buy in t (Runnable R) E.EXECUTE (THREAD T) E.EXECUTE (THREAD T) ANSWER : B

76. which is true? A.If only one thread is blocked in the wait method of an object, and another thread executes the notify method on that same object, then the first thread immediately resumes executes. B. If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, it is still possible that the first thread might never resume execution C.If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, then the first thread definitely resumes execution as a direct and sole consequence of the notify call D.If two threads are blocked in the wait method of one object, and another thread executes the notify method on the same object, then the thread that executed the wait call first definitely resumes execution as a direct and sole consequence of the notify call Answer:. B77 which statement is true A. An anonymous inner class may be d? eclared as final B. An anonymous inner class can be declared as private C. An anonymous inner class can implement mutiple interfaces D. An anonymous inner class can access final variables in any enclosing scope E. Construction of an instance of a static inner class requires An Instance of the Encloing Outer Class Answer: D

78. Public class x {public object m () {3) Object o = new float (3.14f); Object [] OA = new object [1]; OA [0] = 0; o = null; returna [0 ];} }When is the the float object, created in line 3, Collected AS Garbage? A.just After Line 5 B.Just After Line 6 C.Just After Line 7 D. NEVER IN THITHOD ANSWER: D

79. which will declare a method that forces a subclass to implement A.public double methoda () B.abstract public void methoda () Answer:?. B80 // point X public class Foo {public static void main (String [] args ) {PrintWriter Out = New PrintWriter (NEW JAVA.IO.OUTPUTSTREAMWRITER (System.out); OUT.PRINTLN ("Hello");}} WHICH STATEMENT AT POINT X LINE 1 Allows this code to compile and run? A.Import java.io.printwriter B.include java.io.printwriter C.Import java.io.outputStreamWriter D.include java.io.OutputStreamwriter E.NOS NETEMWRITER E.NOS NEEDED ANSWER: A

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

82. 1) Abstract Class Abstract {2) Abstract float getfloat (); 3)} 4) Public class abstractTest Extends Abstract {5) Private float f1 = 1.0F; 6) private float getfloat () {Return F1;} 7) } A: What is the result? B: Compile Fail Online 6 Answer: B

83. Byte [] array1, array2 [] byte array3 [] [] byte [] [] Array4 if Each Has BEEN INITIALIZED, WHICH STATEMENT WILL CAUSE A COMPILE ERROR? A.Array2 = array1 b.Array2 = array3 c.Array2 = Array4 Answer: a

84. Writes the text "" to the end of the file "file.txt"? A.outputstream out = new fileoutputstream ("file.txt"); out.writebytes ("/ n"); B.outputStream OS = new FileOutputStream ( "file.txt", true); DataOutputStream out = new DataOutputStream (os); out.writeBytes ( "/ n"); C.OutputStream os = new FileOutputStream ( "file.txt"); DataOutputStream out = new DataOutputStream (OS); out.writebytes ("/ n"); D.outputStream OS = New OutputStream ("File.txt", True; DataOutputStream Out = New DataOutputStream (OS); Out.WriteBytes ("/ n") Answer: b85. Which constructs a dataoutputstream? A.New DataOutputStream ("out.txt"); B.New DataOutputStream (New File ("out.txt"); c.New DataOutputStream (New Writer ("Out.txt ")); D.New DataOutputStream (New OutputStream (" out.txt ")); E.NEW DataOutputStream (New FileWriter (" out.txt ")); F.New DataOutputStream (New FileoutputSream (" Out.txt ") Answer: f

86. which statement is true for the class java.util.HashSet? A.The elements in the collection are ordered B.The collection is guaranteeded to be immutable C.The elements in the collection are guaranteeded to be unique D.The elements in The Collection Are Access Using A Unique Key E.THE Elements in The Collection Are Guaranteed To Be Synchronized Answer: C

87. 1) Public Abstract Class test {2) public abstract void methoda (); 3) public abstract void methodb () 4) {system.out.println ("hello"); 5)} 6)} Which Three Changes made independently) allow the code to compile A.add a method body to methodA B.replace line 4-5 with a?. ";".. C.remove the abstract qualifier from the declaration of Test D.remove the abstract qualifier from . the declaration of methodB E.remove the abstract qualifier from the declaration of methodA F.remove methodB in its entirety and change class to interface in line 1. Answer:.. B, D, F88 ClassOne.java package com.ab.pkg1 ; public class ClassOne {private char var = 'a'; char getVar () {return var;}} ClassTest.java package com.ab.pkg2; import com.ab.pkg1.ClassOne; public class ClassTest extends ClassOne {public static Void main (string args []) {char A = new classone (). getvar (); char b = new classtest (). getvar ();}} wh AT Is The Result? Answer: CIMPILE Error

89. INT i = 1, J = 10; Do {IF (i> j) Continue; J -; i <6); What Are the Vale of i and j? Ai = 6, j = 5 Bi = 5, J = 5 Ci = 6, j = 4 di = 5, J = 6 EI = 6, J = 6 Answer: a

90. Public class foo {public static void main (string [] args) {INT i = 1; INT j = i ; if ((i> j) && (i == j)) {i = j;} }} What is the final value I and j? Answer: i = 2, j = 2

91. Which Two Are Equivalent? A.16> 4 B.16 / 2 C.16 * 4 D.16 >> 2 E.16 / 2 ^ 2 F.16 >>> 2 Answer: d, f

92. Public class x {public static void main (string [] args) {BYTE B = 127; 4) Byte C = 126; 5) Byte D = B C;}} A.Line 5 throws an exception indeption indeption indeption of range "B.Line 5 cause a compile fail C.compile succeeded Answer:. B93 AnInterface is an interface AnAdapter0 is a non-abstract, non-final class with a zero argument constructer AnAdapter1 is a non-abstract, non-final class without a zero argument constructer, but with a constructer that takes one int argument which two create an anoymous inner class? A.AnAdapter0 aa = new AnAdapter0 () {} B.AnAdapter1 aa = new AnAdapter1 (5) {} C.AnAdapter1 aa = new anadapter1 () {} D.anadapter0 aa = new anadapter0 (5) {} E.aninterface ai = new aninterface (5) {} ANSWER: A, B

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

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

96. Which can be used to encode Chars for Output? A.java.io.outputstreamwriter B.java.io.FileOutputStream C.java.io.DataOutputStream Answer: a

97. Which determines if "prefs" IS A DIRECTORY AND EXIST on the file system? A.BOOLEAN EXISTS = (New File ("prefs")). Isdirectory (); B.BOOLEAN EXISTS = (New File) .isdir (); answer: a

98.Which code determines the int value foo closest to, but not greater tran, a double value bar? A.int foo = (int) math.max (bar); B.int foo = (int) Math.min (bar ); C.int foo = (int) Math.Abs ​​(bar); D.Int foo = (int) Math.ceil (bar); E.int foo = (int) Math.Floor (bar); f.int Foo = (int) math.Round (bar); answer: e99. Import java.awt. *; public class test (); ad (New Label ("Hello"); add (New Textfield "Hello"); Add ("Hello"); pack (); // borderLayout --The Four Area Around Will Be Lost Show (); public static void main (String [] args) {new Test ();}} What is the result? Answer: center is only a button "Hello" and Has A Window "Test"

100. which is true? A. Any statement that may throw an Exception must be enclosed in a try block. // Standard Exception (Runtime Exception) is not B. Any statement that may throw an Error must be enclosed in a try block. C. Any Statement That May Throw An RuntimeException Must Be Enclosed in A Try Block. D. No Exception Are Subclass of Error. Answer: D

101. which one is true? A.An anonymous class can be declared as static. BA static inner class can not be a static member of the outer class. CA static inner class does not require an instance of the enclosing class. D.Instance member OF A Static Inner Class Can Be Reference Using The Class Name of The Static Inner Class. Answer: C

102.public class MyCircle {public double radius; public double diameter; public void setRadius (double radious) {6) this.radius = radius; 7) this.diameter = radius * 2;} public double getRadius () {return radius; }} A. The MyCircle class is fullly encapsulated B. The diameter of a given MyCircle is guaranteed to be twice its radius. C. Line 6 and 7 should be in a Synchronized block to ensure encapsulation. D. The radius of a MyCircle object CAN be set without affecting its diameter. Answer: d103.given: public class arraylist {public static void main (string [] args) {float f1 [], f2 []; f1 ​​= new float [10]; f2 = f1; System.out.println ("F2 [0] =" F2 [0]);}} What is the result? Answer: 0.0

104.Public class x {public static void main (string [] args) {int [] a = new int [1]; 4} modify (a); system.out.println (a [0]);} public static Void modify (int [] a) {9} a [0] ;}} What is the result? a.The Program Runs and Prints "0"; B.The Program Runs and Prints "1"; C.THE Program Runs But Aborts with an exception; D.an error "Possible undefined variable" at line 4 cause compilation to fail; E.N Error "Possible undefined variable" at line 9 Cause Compilation To Fail; Answer: B

转载请注明原文地址:https://www.9cbs.com/read-110324.html

New Post(0)