question 1)
+ L% ] {+ B( Uwhich of the following lines will compile without warning or error.
( R) n' |% }4 \6 p: Y/ o1) float f=1.3;
. S( e. U, U7 q% b- Q6 i. G2) char c='a';
. @4 H2 j) w: R# G1 q3) byte b=257;
5 @$ k: b2 R3 F/ n. v7 O6 i/ L4) boolean b=null;
5 \" y' \: }% K+ _; U |5) int i=10; ( Z5 Z) W3 U" ]4 Q
answer to question 1 & P" D, M8 |- ^' O
--------------------------------------------------------------------------------
]' A9 d# |( y& R! |question 2)
% x6 Y$ L0 U/ T2 ^3 p& Vwhat will happen if you try to compile and run the following code
3 _. V) G3 g2 f% M) P% {, Tpublic class myclass { / s9 `5 t' S$ |8 e# s
public static void main(string arguments[]) {
1 E0 c- l! q" r( U4 ?amethod(arguments); 5 X5 l9 P6 N1 J' Y
} ( m+ g% V! W* L3 t4 B/ _+ ~
public void amethod(string[] arguments) {
3 h1 _' v# l, N4 H0 S4 @system.out.println(arguments); 2 x8 [ t& n8 V4 m% M6 {3 p- e
system.out.println(arguments[1]); / i% y1 d/ ]& b+ u# V- |
} ! v; A3 [ ^, K1 I$ [% g
} 1 ~4 {* \' s4 {; L& v% z$ x2 s
1) error can´t make static reference to void amethod.
: X+ i/ {, A- Y! `2) error method main not correct
( P8 F$ N Y. a R, S3) error array must include parameter
$ a l- S. L. F j: E4) amethod must be declared with string
! U0 _* |( N2 T4 q( w& f. Zanswer to question 2
4 s7 E% a b6 w/ `$ L4 ?4 Z-------------------------------------------------------------------------------- ' t' n4 ]; |5 b' @' f; [7 w
question 3) ; q8 ^' E+ w+ y2 `; C- U& S
which of the following will compile without error
( S2 e9 p" c. T6 q$ G1 X z+ V1 b1) 2 R! ~2 `' C: z8 n
import java.awt.*; , ?7 W, G% G: ]. I( H% j x
package mypackage;
; p7 d: J7 {) T! U) o" kclass myclass {} 5 ]& w$ k3 k" e# d) x; Q
2) 9 G: z0 t% v* U/ S& l9 r2 O
package mypackage; 8 U- ^# a2 S3 z. d. P' e( S
import java.awt.*; 8 l7 g2 ~6 n; Z' M
class myclass{} 8 E; s* Z5 i3 K! e2 K
3)
% }$ \: G1 @$ w t2 T7 \/*this is a comment */ 4 i3 S# L. A$ S- y
package mypackage;
0 u, P$ I) i6 P/ n5 Y. Ximport java.awt.*; ' G) w( |( T# F; M
class myclass{}
( |8 k6 k, @$ K. v" f# F( P' panswer to question 3 ) j' U! _" d' U: v4 t( n/ B
--------------------------------------------------------------------------------
9 q( e3 G8 w6 gquestion 4)
6 R' ?0 k# }0 [$ V, ]" za byte can be of what size
+ y4 b& M0 C& `* Y4 }1) -128 to 127 0 {! q6 j2 m/ i/ [
2) (-2 power 8 )-1 to 2 power 8
) R$ H1 V [0 ] q K& _; O5 N3) -255 to 256
! v4 e7 p8 Y2 J9 ^4)depends on the particular implementation of the java virtual machine
3 C; h4 C( ^& S7 ~$ Z9 }. J; nanswer to question 4 $ J) W( h; U) n4 c
-------------------------------------------------------------------------------- ( Y# |* M j ]: K1 U* Z: q4 k( [
question 5) " ^, I! Q: D U) c/ x( l4 H
what will be printed out if this code is run with the following command line? - {6 t$ A2 ]7 t# T$ x+ _ B
java myprog good morning & G$ l' M1 I9 C3 F3 b0 H
public class myprog{
' }+ _) U( [2 a9 ^- X' Npublic static void main(string argv[])
5 M7 Y6 z# i8 @& F) V' w{ . N# R# ?2 b; q) B
system.out.println(argv[2]) 1 l( u! W+ M( N. x" ? B
} % T+ H2 ~' D$ f, q5 y- g# P x3 H9 {
} ; Y, k* i& `1 f6 T- o+ y& G2 |
1) myprog
! m) Y8 h5 I5 p1 n2) good 0 L: e% c7 n8 a0 [" \4 r
3) morning % v6 {" ]; x& D- E, O- {8 K6 Y
4) exception raised: 'java.lang.arrayindexoutofboundsexception: 2' 4 K5 q- L8 w- G! K9 g) i, p
answer to question 5
/ }" O, x; r' D; S-------------------------------------------------------------------------------- & u* y) W2 N+ x2 u
question 6) , e) X. v( j! ~: T
which of the following are keywords or reserved words in java? 2 o, `7 I: a2 J* w% o
1) if
# H2 T2 ]+ V6 z% \: y2) then 0 j' ^ N' e. H* x+ p
3) goto
& D6 G; O+ d: I5 ]1 o" |4) while
* b3 }/ | q; ]$ `$ Y1 k) d- v4 l, ^' f2 | D' }6 Z$ R9 u
which of the following statements are true? + I0 e `: F m, e0 x" j
1) methods cannot be overriden to be more private 8 H. z `0 W2 K7 y7 T9 ]
2) static methods cannot be overloaded
6 R5 d% g+ i% f+ w0 @- e! h7 g3) private methods cannot be overloaded
/ V9 }! G! @9 c U9 w! g) S9 }4) an overloaded method cannot throw exceptions not checked in the base class
/ q) Z* n) c- H( W, {$ C, Z0 [answer to question 16
' \( h2 N, e. \-------------------------------------------------------------------------------- |