📄 认证与培训 - 希望对大家有帮助(280道考题回忆).mht
字号:
main(String args[]){<BR>8. thisMethod();<BR>9. =
}<BR>10.=20
}
<P>1. Will compile fine,but at runtime a=20
ClassCastException is thrown<BR>2. Will compile =
and run=20
fine<BR>3. Compiler error at line 4<BR>4. =
Compiler error=20
at line 5
<P>Ans: 2
<P>62.public class Outer{<BR>//////<BR>}
<P>What should be inserted at ///// so that the =
code=20
will compile<BR>fine?(Choose two)
<P>1. private class Inner{<BR>static int k;<BR>}
<P>2. static class Inner{<BR>static int k;<BR>}
<P>3. public class Inner{<BR>static int k;<BR>}
<P>4. public abstract class Inner{<BR>public =
abstract=20
void method();<BR>}
<P>Ans: 2,4
<P>
<P>63.What will be the output when following =
code is=20
run?
<P>1. class ThisClass{<BR>2. static void foo() =
throws=20
Exception{<BR>3. throw new Exception();<BR>4. =
}<BR>5.=20
public static void main(String args[]){<BR>6. =
try{<BR>7.=20
foo();<BR>8. }catch(Exception e){<BR>9.=20
System.exit(0);<BR>10. }<BR>11. finally{<BR>12.=20
System.out.println("In finally");<BR>13. =
}<BR>14.=20
}<BR>15. }
<P>1. Compiler error.<BR>2. Code will compile =
fine and=20
when run prints In finally.<BR>3. Nothing will =
be=20
printed.<BR>4. Runtime exception.
<P><BR>Ans 2
<P>64.import java.awt.*;<BR>class X extends=20
Frame{<BR>X(){<BR>setLayout(new=20
BorderLayout());<BR>setSize(600,600);<BR>Panel =
p=3Dnew=20
Panel();<BR>Button b1=3Dnew=20
Button("Button1");<BR>p.add(b1);<BR>Button =
b2=3Dnew=20
=
Button("Button2");<BR>add(p,BorderLayout.NORTH);<BR>add(b2,BorderLayout.S=
OUTH);<BR>setVisible(true);<BR>}<BR>public=20
static void main(String args[]){<BR>new =
X();<BR>}<BR>}
<P>How the components are displayed on the =
frame?
<P>1. Components will be of equal size.
<P>2. Button1 will be placed at top center and =
Button2=20
will occupy<BR>rest of the area.
<P>3. Button2 will be placed at top center of =
the frame=20
and Button1<BR>will be placed at bottom center =
of the=20
frame.
<P>4. Button2 will be placed at top center of =
the frame=20
and Button1<BR>will be placed at bottom of the =
frame=20
from left end to right end.
<P>5. Button1 will be placed at top center of =
the frame=20
and Button2<BR>will be placed at bottom of the =
frame=20
from left end to right end.
<P>Ans 5
<P>
<P>65.File f=3Dnew File("aa.txt");<BR>Suppose =
this file=20
exists in your directory.<BR>Which of the =
following can=20
be used to write a line of text to the<BR>end of =
this=20
file?
<P>1. RandomAccessFile f1=3Dnew=20
RandomAccessFile(f,"r");<BR>2. RandomAccessFile =
f1=3Dnew=20
RandomAccessFile(f,"a");<BR>3. RandomAccessFile =
f1=3Dnew=20
RandomAccessFile(f,"rw");<BR>4. RandomAccessFile =
f1=3Dnew=20
RandomAccessFile(f,"w");<BR>5. RandomAccessFile =
f1=3Dnew=20
RandomAccessFile(f,"wr");
<P>Ans 3
<P>
<P>66.What is the value of j when printed?
<P>class Foo{<BR>public static void main(String=20
args[]){<BR>int =
x=3D4,j=3D0;<BR>switch(x){<BR>case=20
1:j++;<BR>case 2:j++;<BR>case 3:j++;<BR>case=20
4:j++;<BR>case=20
=
5:j++;<BR>break;<BR>default:j++;<BR>}<BR>System.out.println(j);<BR>}<BR>}=
<P>1. 1<BR>2. Compiler error<BR>3. 6<BR>4. =
3<BR>5. 2
<P>Ans 2
<P>67.What will be the content of baz after the =
the=20
following code is run?
<P>class A{<BR>public static void main(String=20
args[]){<BR>String bar=3Dnew =
String("blue");<BR>String=20
baz=3Dnew String("green");<BR>String var=3Dnew=20
String("red");<BR>String=20
=
c=3Dbaz;<BR>baz=3Dvar;<BR>bar=3Dc;<BR>baz=3Dbar;<BR>System.out.println(ba=
z);<BR>}<BR>}
<P>1. red<BR>2. Compiler error<BR>3. blue<BR>4.=20
null<BR>5. green
<P>Ans 5
<P>68.import java.io.*;<BR>class =
Excep{<BR>static void=20
method() throws Exception{<BR>throw new=20
EOFException();<BR>}
<P>public static void main(String=20
=
args[]){<BR>try{<BR>method();<BR>}catch(////){}<BR>}<BR>}
<P>Which of the following should be placed at =
//// so=20
that the code will<BR>compile without errors?
<P>1. IOException e<BR>2. EOFException e<BR>3.=20
MalformedURLException e<BR>4. =
NullPointerException=20
e<BR>5. Exception e<BR>6. FileNotFoundException
<P>Ans 5
<P>69. What will be the output when the =
following code=20
is run?<BR>1. class ThisClass{<BR>2. public =
static void=20
main(String args[]){<BR>3. Object =
o=3D(Object)new=20
ThisClass();<BR>4. Object s=3Dnew =
Object();<BR>5.=20
if(o.equals(s))<BR>6. =
System.out.println("true");<BR>7.=20
}<BR>8. }
<P>1. Prints true<BR>2. Nothing will be =
printed<BR>3.=20
Compiler error at line 3<BR>4. Compiler error at =
line=20
5<BR>5. ClassCastException will be thrown
<P>Ans 2
<P>70.Which of the following interfaces that =
ArrayList=20
directly<BR>implements?
<P>1. Set<BR>2. Map<BR>3. SortedSet<BR>4. =
List<BR>5.=20
Collection
<P>Ans 4
<P>71.What will be the output when following =
code runs?
<P>1. class C1{<BR>2. static int j=3D0;<BR>3. =
public void=20
method(int a){<BR>4. j++;<BR>5. }<BR>6. }<BR>7. =
class=20
Test extends C1{<BR>8. public int =
method(){<BR>9. return=20
j++;<BR>10. }<BR>11.<BR>12. public void =
result(){<BR>13.=20
method(j);<BR>14. =
System.out.println(j+method());<BR>15.=20
}<BR>16. public static void main(String =
args[]){<BR>17.=20
new Test().result();<BR>18. }<BR>19. }
<P>1. 3<BR>2. 2<BR>3. Compiler error at line =
8<BR>4.=20
1<BR>5. 0
<P>Ans 2
<P>72.What will be printed when following code=20
runs?<BR>1. class Foo{<BR>2. static void =
change(String=20
s){<BR>3. s=3Ds.replace('j','l');<BR>4. =
}<BR>5.<BR>6.=20
public static void main(String args[]){<BR>7. =
String=20
s=3D"java";<BR>8. change(s);<BR>9.=20
System.out.println(s);<BR>10. }<BR>11. }
<P>1. Compiler error<BR>2. Will print lava<BR>3. =
Runtime=20
exception<BR>4. Will print java
<P>Ans 2
<P>########
<P>74. 1.public static void main(String =
args[]){<BR>2.=20
byte b=3D127;<BR>3. byte c=3D126;<BR>4. byte =
d=3Db-c;<BR>5.=20
System.out.println(d);<BR>6.}
<P>a) Compilation succeeds and prints 1.<BR>b)=20
Compilation succeeds but there will a Runtime=20
Exception.<BR>c) Compilation error at line no =
4.<BR>d)=20
Compilation error at line no 5.
<P>Ans c
<P>75. Which is the valid identifier?
<P>a) 123_hello<BR>b) _12345<BR>c) !hello<BR>d)=20
&sample
<P>Ans B
<P>76. Which two values are equal?
<P>a) 16<<2<BR>b) 16/3*2<BR>c) =
16>>2<BR>d)=20
16<<<2<BR>e) 16>>>2<BR>f) 16/2
<P>Ans CE
<P>77. What is true about anonymous inner class?
<P>a) Anonymous inner class can be declared as=20
public.<BR>b) Anonymous inner class can be =
declared as=20
private.<BR>c) Anonymous inner class can be =
declared as=20
static.<BR>d) Anonymous inner class can extend =
an=20
abstract class.<BR>e) Anonymous inner class can =
be=20
declared as protected.
<P>Ans D
<P>78. Which will return an int value very =
nearer to and=20
not greater than<BR>the given double value?
<P>a) int a=3D(int)Math.max(double)<BR>b) int=20
a=3D(int)Math.min(double)<BR>c) int=20
a=3D(int)Math.ceil(double)<BR>d) int=20
a=3D(int)Math.floor(double)<BR>e) int=20
a=3D(int)Math.round(double)
<P>Ans d
<P>79. 1.import java.io.IOException;<BR>2.class =
Happy=20
{<BR>3. public static void main(String args[]) =
{<BR>4.=20
try {<BR>5. method1();<BR>6. }<BR>7. =
catch(IOException=20
e) {<BR>8. System.out.println("Catch=20
IOException");<BR>9. }<BR>10. =
catch(ArithmeticException=20
e) {<BR>11. System.out.println("Catch=20
ArithmeticException");<BR>12. }<BR>13. finally =
{<BR>14.=20
System.out.println("Catch Finally");<BR>15. =
}<BR>16.=20
}<BR>17.<BR>18. public void method1() throws=20
IOException{<BR>19. throw new =
IOException();<BR>20.=20
}<BR>21.}
<P>a) Compilation succeeds and prints "Catch=20
IOException" and "Catch<BR>Finally".<BR>b) =
Compilation=20
succeeds but there will be a run time =
exception.<BR>c)=20
Compilation error at line no.10<BR>d) =
Compilation error=20
at line no.5<BR>e) Compilation error at line =
no.19
<P>Ans D
<P>80. Which method is used to construct and =
execute the=20
thread?
<P>a) execute()<BR>b) run()<BR>c) build()<BR>d) =
start()
<P>Ans D
<P><BR>81. import java.io.IOException;<BR>class =
Happy=20
{<BR>public static void main(String args[]) =
{<BR>try=20
{<BR>//code which throws an=20
IOException<BR>}<BR>catch(IOException e)=20
{<BR>System.out.println("Catch=20
IOException");<BR>}<BR>catch(Exception e)=20
{<BR>System.out.println("Catch=20
Exception");<BR>}<BR>}<BR>}
<P>a) Compilation error complaining about class =
Excepion=20
have not been<BR>imported.<BR>b) Clean =
compilation but=20
run time Exception is thrown.<BR>c) Execute =
fine.
<P>Ans C<BR>// Code runs wih out any problem
<P>82. switch(s) {<BR>default: =
System.out.println("Best=20
Wishes");<BR>}<BR>Which datatype can 's' be?
<P>a) byte<BR>b) long<BR>c) float<BR>d) double
<P>Ans A
<P>83. public static void main(String args[]) =
{<BR>in
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -