22. Which are correct class declarations? Assume in each case text constitutes the entire contents of a file called Fred.java on a system4 Q2 B0 V- E, g7 T6 K
with a case-significant system.
0 ]6 x6 }( S2 [" D1 GA. public class Fred {
" K& h# p! o3 w. a3 c$ q5 U. `public int x = 0;
* ]4 p0 Z/ [5 f2 L/ m9 npublic Fred (int x) {" b8 j# Z8 s$ r) S
this.x = x;. Z0 h1 S* r9 a/ h0 T& Z
}1 j, [9 D& F; ]3 C& d! B/ J& ]
}$ q3 y& T* { y! c2 H* |- U
B. public class fred {% F1 K# t- h2 ?+ a5 G* b
public int x = 0;+ k r( U% ^$ L& ^
public fred (int x) {
; _( p2 ?5 i. C# Hthis.x = x;- s1 l4 d9 r; x3 Z
}# ~0 d; Y _$ C3 y( g, v
}2 l, l7 i' h- A: p# h
C. public class Fred extends MyBaseClass, MyOtherBaseClass {4 q9 C+ B3 c! {
public int x = 0;
2 h8 `- e* p) G' Tpublic Fred (int xval) {# {, b5 |& f* D. H9 ?
x = xval;; v, ]& U' p8 }! l W
}
: |, o. f7 w! k, p$ P, _' P8 p}0 R, }' e/ x0 Q/ p9 A$ Q
D. protected class Fred {2 y/ o3 U. s+ \& F0 y7 h/ v
private int x = 0;
( |8 F" ]' D2 Yprivate Fred (int xval) {6 X4 H$ u: W& w
x = xval;$ n% h8 X4 N, ]$ P
}( W# Z$ b0 F4 w- x' ~1 P2 w) K" n
}6 l! c0 B1 o6 c2 G! L8 r
E. import java.awt.*;
& W4 {; |1 F j- U3 e, spublic class Fred extends Object {
" p6 W' ?) L ]) o+ l6 z* V# jint x;$ e. w0 Q! l* x% F
private Fred (int xval) {
! {7 Z# h) q0 _8 tx = xval; }" @: x3 v$ A4 {8 J& K0 s
}
! z9 T3 b& S) x# a: l- a$ \8 {( V}' Y1 z# C8 {1 q |, @) B
AE.
5 O6 W9 C1 B) ~0 N& YB is wrong because of case-sensitivity. C is wrong because multiple inheritance is not supported in Java. D is wrong because a class can
. V- G: ]- v, M" K) gonly be public, abstract, final or default (with no access modifier). |