📄 认证与培训 - 希望对大家有帮助(280道考题回忆).mht
字号:
give throw Exception and inside the =
method<BR>give=20
throws Exception<BR>B. In method declaration =
give throws=20
Exception and inside the method<BR>give throw=20
Exception<BR>C. In method declaration give throw =
Exception and inside the method<BR>give throw=20
Exception<BR>D. In method declaration give =
throws=20
Exception and inside the method<BR>give throws=20
Exception<BR>Ans:A<BR>34. class =
Sreejith<BR>{<BR>public=20
static void main(String=20
=
args[])<BR>{<BR>try{<BR>///ProtocolException<BR>}<BR>catch(IOException=20
=
e)<BR>{System.out.println("I");}<BR>catch(Exception=20
=
e)<BR>{System.out.println("E");}<BR>finally{System.out.println("F");}<BR>=
}<BR>}<BR>//Exception=20
is the super class of IOException and =
IOException is=20
the<BR>super class of ProtocolException
<P>if a ProtocolException occurs in try block =
what will=20
be the out put?<BR>Select all<BR>A. I<BR>B. =
E<BR>C.=20
F<BR>D. Compilation Error says that there is no =
matching=20
catch block<BR>Ans:AC
<P>35.public static void main(String =
args[])<BR>{<BR>int=20
a=3D10;<BR>int =
b=3D20;<BR>if(a=3Db)<BR>System.out.println("Not=20
=
Equal");<BR>else<BR>System.out.println("Equal");<BR>}
<P>What will be the output?<BR>A. Equal<BR>B. =
Not=20
Equal<BR>C. Compilation Error<BR>D. An Exception =
will=20
occurs<BR>Ans:C<BR>//because if will return a =
number
<P>36. public static void main(String =
args[])<BR>{
<P>int=20
=
t=3D0;<BR>while(1)<BR>{<BR>if(t++<10)<BR>break;<BR>}<BR>}<BR>What=20
will be the value of 't 'after the while loop =
?<BR>A.=20
11<BR>B. 9<BR>C. 10<BR>D. Compilation =
Error<BR>E. An=20
Exception will occurs<BR>Ans:D
<P>37. Which of the following will give correct=20
declaration statement for<BR>float select =
3<BR>A. float=20
f=3D 1.0;<BR>B. float f=3D 3.222e+1;<BR>C. float =
f=3D=20
-1;<BR>D. float f=3D 1;<BR>E. float f=3D1.0f;
<P>Ans:cde
<P>38. public static void main(String=20
args[])<BR>{<BR>int t=3D0xffff1;<BR>int=20
j=3D~t;<BR>System.out.println(j);<BR>}
<P>What will be the output?<BR>A. -1048562<BR>B. =
-10<BR>C. Exception<BR>D. Compilation Error
<P>Ans:A<BR>//when you will use ~ then the +ive =
will=20
become -ve
<P>39. package foo;<BR>class a{int c}<BR>class =
b{private=20
int d}<BR>class c{public int e}<BR>which can =
class=20
access all the variables in the limit foo?
<P>A. class a<BR>B. class b<BR>C. class c<BR>D.=20
none<BR>Ans:B
<P>40.<BR>1.interface foo<BR>2. {<BR>3. int =
I=3D0;<BR>4.=20
}<BR>5. class sreejith implements foo<BR>6.=20
{<BR>7.public static void main(String=20
args[])<BR>8.{sreejith s =3Dnew =
sreejith();<BR>9. int=20
=
j=3D0;<BR>10.j=3Ds.I;<BR>11.j=3Dsreejith.I;<BR>12.=20
j=3Dfoo.I;<BR>13. s.I=3D2;<BR>}<BR>}<BR>Where =
will=20
compilation Fail?<BR>A.10<BR>B. =
11<BR>C.12<BR>D.13<BR>E.=20
No error<BR>Ans:D<BR>//variables inside the =
interface=20
are by default public static final
<P>41. Which of the following will create an =
array that=20
can be used for 50<BR>Strings? select 2
<P>A. char a[][]<BR>B. String a[]<BR>C. =
String[]a;<BR>D.=20
String a[50];
<P>Ans: BC
<P>42. Where will be a 'is a ' relationship will =
occur=20
select one?
<P>A. interface Person<BR>class Employee =
implements=20
Person<BR>B. interface Shape<BR>interface =
Rectangle=20
extends Shape<BR>C. interface Component<BR>class =
Objects=20
implement Component<BR>{Component [] Component;}
<P>Ans:B
<P>43. What will be the return type of=20
the<BR>(short)10/10.2*2;<BR>A. short<BR>B. =
int<BR>C.=20
double<BR>D. float<BR>E. Compilation =
Error<BR>Ans:C
<P>44.Write the value for the =
following?<BR>6^3<BR>Ans:=20
5
<P>45. What is the modifier is used for a =
variable in=20
the class to be<BR>accessed in subclass =
only?<BR>A.=20
public<BR>B. none<BR>C. protected<BR>D. =
private<BR>Ans:C
<P>46. What is the modifier is used to make a =
method to=20
be overridden<BR>in subclass?<BR>A. final<BR>B.=20
abstract<BR>C. static<BR>D. volatile
<P>Ans:B<BR>47. class sreejith<BR>{<BR>String=20
s;<BR>public static void main(String=20
args[])<BR>{<BR>sreejith ks=3Dnew =
sreejith();<BR>int=20
=
j,i;<BR>i=3Dks.hai();<BR>j=3Dks.hello();<BR>System.out.println(i+"=20
"+j);<BR>}<BR>int hai()<BR>{<BR>if =
(s=3D=3Dnull)||=20
(s.length()=3D=3D0))<BR>return 10;<BR>else =
return=20
0;<BR>}<BR>int hello()<BR>{<BR>if (s=3D=3Dnull)| =
(s.length()=3D=3D20))<BR>return 10;<BR>else =
return=20
0;<BR>}<BR>}<BR>what will be printed out?<BR>A. =
10=20
10<BR>B. 10 null<BR>C. 0 0<BR>D. Compilation =
Error<BR>E.=20
An Exception in hai<BR>F. An Exception in =
hello<BR>Ans:F
<P>48. Which are keywords in Java? Select =
2<BR>A.=20
transient<BR>B. true<BR>C. sizeof<BR>D. =
implement<BR>E.=20
synchronize<BR>Ans:AB<BR>49. 1. class =
sreejith<BR>2.=20
{<BR>3. public static void main(String =
args[])<BR>4.=20
{<BR>5. String s=3D"hello";<BR>6. String =
s1=3D"hello";<BR>7.=20
System.out.println(s1);<BR>8. String =
s3=3Ds1;<BR>9.=20
s1=3Dnull;<BR>10. s=3Dnull;<BR>11. }<BR>Which =
line the=20
garbage collector will invoke first?
<P>Ans: never invoke in this method
<P>50. To Read a File f=3Dnew =
File(C:\\hello.txt"); select=20
all;
<P>new=20
=
RandomAccessFile(f,"rw").readByte(?;<BR>FileInputStream=20
fis=3Dnew FileInputStream(f);<BR>DataInputStream =
d=3Dnew=20
=
DatainputStream(fis);<BR>d.readBytes(?<BR>FilterInputStream=20
fis=3Dnew =
FilterInputStream(f,true);<BR>DataInputStream=20
d=3Dnew =
DatainputStream(fis);<BR>d.readBytes(?<BR>D.=20
FileOutputStream fis=3Dnew=20
FileOutputStream(f);<BR>DataOutputStream d=3Dnew =
DataOutputStream(fis);<BR>d.readBytes(?<BR>E.=20
FilterOutputStream fis=3Dnew=20
FilterOutputStream(f,true);<BR>DataOutputStream =
d=3Dnew=20
=
DataOutputStream(fis);<BR>d.readBytes(?<BR>Ans:AD
<P>51.<BR>public static void main(String=20
args[])<BR>{<BR>int j=3D10;<BR>int =
I=3D1;<BR>do<BR>{<BR>if=20
=
(I++>--j)<BR>continue;<BR>}while(I<5);<BR>}<BR>what=20
will be the value of I and j after the =
loop?<BR>Ans: I=3D5=20
J=3D6
<P>52.<BR>What should you use to position a =
Button=20
within an application frame so<BR>that the =
vertical of=20
the Button is only affected when you will =
resize<BR>the=20
window?<BR>A. FlowLayout<BR>B. GridLayout<BR>C. =
Center=20
area of a BorderLayout<BR>D. East or West of a=20
BorderLayout<BR>E. North or South of a=20
BorderLayout<BR>Ans: D
<P>53.<BR>class c extends=20
Frame<BR>{<BR>c(){<BR>setLayout(new=20
BorderLayout());<BR>Panel p1,p2;<BR>p1=3Dnew=20
Panel();<BR>p2=3Dnew Panel();<BR>p1.add(new=20
Button("B1");<BR>p2.add(new =
Button("B2");<BR>add(new=20
=
Button("B3"));<BR>setsize(300,300);<BR>setVisible(true);<BR>}<BR>public=20
static void main(String args[])<BR>{<BR>c o =3D =
new=20
c();<BR>}<BR>how will be buttons displayed?
<P>Ans: Only button 3 will displayed and will =
occupy=20
entire frame
<P>54.<BR>public static void main(String=20
a[])<BR>{<BR>StringBuffer s=3Dnew=20
StringBuffer("Java");<BR>String c=3Dnew=20
=
String("Java");<BR>Hello(s,c);<BR>System.out.println(s+c);
<P>}<BR>public static Hello(StringBuffer s, =
String=20
=
c)<BR>{<BR>s.append("C");<BR>c.repalce('A','D')<BR>}<BR>Write=20
the Output?<BR>Ans: JavaCJava
<P>55.<BR>class Outer{<BR>class static=20
Inner{}<BR>}<BR>How will you create an instance =
of=20
static Inner Class? Select 2<BR>Inner a=3D new=20
Inner();<BR>Outer o=3D new Outer();Outer.Inner =
a=3D new=20
o.Inner();<BR>Outer.Inner a=3D new Outer.new=20
Inner();<BR>Outer.Inner a=3D new Outer.Inner();
<P>Ans: BD<BR>56. . Write the range of int in =
values
<P>-2147483648 TO + 2147483647
<P>57. which will contain the body of the=20
=
thread<BR>run()<BR>start()<BR>stop()<BR>main()<BR>init()<BR>Ans:=20
A
<P><BR>57.Which of the following will give equal =
results?<BR>3/2 b.3<2 c. 3*4 d. =
3<<2<BR>Ans: cd
<P>58.<BR>StringBuffer b=3Dnew=20
=
StringBuffer();<BR>try{<BR>b.append("1");<BR>method();<BR>b.append("2");<=
BR>}<BR>catch(Exception=20
a){<BR>b.append("3");
=
<P>}<BR>finally{<BR>b.append("4");}<BR>b.append("5");<BR>what=20
will be the value of ' b' if the method=20
throws<BR>NullPointerException?
<P>Ans: 1345
<P>59.<BR>if a method throws an=20
ProtocolException(subclass of IOException) =
which<BR>of=20
the following can be used in declaring that =
method<BR>a.=20
public void method() throws Exception<BR>b. =
public void=20
method() throw Exception<BR>c. public throws =
IOException=20
void method()<BR>d. public void method() throws=20
IOException.<BR>e. public void method() throws=20
ProtocolException.
<P>Ans:DE
<P>60.What is the output when following code is =
run=20
?<BR>1. class ForLoop{<BR>2. public static void=20
main(String args[]){<BR>3. int =
i=3D0,j=3D5;<BR>4. st:=20
for(;;i++){<BR>5. for(;;j--){<BR>6. =
if(i>j)<BR>7.=20
break st;<BR>8. }<BR>9. }<BR>10.=20
System.out.println("i=3D"+i+" j=3D"+j);<BR>11. =
}<BR>12. }
<P>1. i=3D0 j=3D-1<BR>2. i=3D1 j=3D0<BR>3. i=3D0 =
j=3D1<BR>4. i=3D1=20
j=3D-1<BR>5. Compiler error at line 4.
<P>Ans : 1
<P><BR>61.What is the output when folllowing =
code is=20
run?
<P>1. class OuterOne{<BR>2. class InnerOne =
extends=20
OuterOne{}<BR>3. static void thisMethod(){<BR>4. =
Object=20
o=3D(Object)new OuterOne();<BR>5. OuterOne=20
foo=3D(OuterOne)o;<BR>6. }<BR>7. public static =
void=20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -