(11),具体内容如下: * I2 I! h2 e" O$ ?
31. Given this skeleton of a class currently under construction:
* Y% `% n" M1 o' u6 Gpublic class Example {! D; k6 `8 J, @& U
int x, y;" x# e$ K" V2 a+ Q
public Example(int a){
* E7 b3 n" }/ I5 E//lots of complex computation( @/ `/ w; v6 I
x = a;/ i1 i s3 ]8 u- J
}
: J) P- U* ^6 ^% z, upublic Example(int a, int b) {% ~8 D5 [% G7 S; z1 o7 q
/*do everything the same as single argument version of constructor including assignment x = a */+ d% g6 |4 h, l9 x
y = b;
6 H& S; L8 P' X D( h! [- r}/ u0 |. C" j; v/ j
}" B& T* D- o# v' w, v; \, W
What is the most concise way to code the "do everything..." part of the constructor taking two arguments?( C, c( X& J; ` _- |
Answer:
* w, c. G+ L- L& V) Dthis(a);
, X! X7 [# D+ K32. Given this skeleton of a class currently under construction:
9 L5 o* d$ Z1 z. t& T( Rpublic class Example {8 d, U! A" V0 t" [; p8 v6 i/ w8 m" a
int x, y;3 B) H; a/ P: P: \/ L
public Example(int a, int b){
% i4 [: _# j! {- t) a7 a, N8 R0 w//lots of complex computation
) `# b* Z& B0 t3 Wx = a; ^# ]6 n& V$ |2 H0 r% `. F& N3 u
}9 e7 I! {( I" Z2 V( s1 {
public Example(int a, int b, long c) {
4 }' H( G ]7 F" |$ T# T% F/*do everything the same as the two argument version of constructor including assignment x = a */8 G& U( t4 |, d. n% ^
y = b;, w+ D4 T0 L$ [$ M$ q
}: M( B7 V; l: |5 A) j
}
( N! P: a7 |! N4 F$ QWhat is the most concise way to code the "do everything..." part of the constructor taking two arguments?
7 P& u* P' \5 t5 t2 g/ Q' FAnswer:
. M5 i; A. t D; Q$ y# gthis(a, b);- Y7 [/ d8 i8 p3 P% {
Warning! A similar question will appear with at least two classes, then it is super("arguments"); that you should use.6 @( ]; A/ ] g5 z4 W) q
33. Which correctly create a two dimensional array of integers?* O/ S Y7 d. B F/ f+ a
A. int a [][] = new int [10,10];7 G& V1 Z% a8 M6 {: p+ S V9 ?
B. int a [10][10] = new int [][];. n5 B6 _# G- b" t; t
C. int a [][] = new int [10][10];5 w4 s. s7 W$ c# ]3 k$ b( J
D. int []a[] = new int [10][10];
- Y- I9 T. X- o dE. int [][]a = new int [10][10];, U# M+ w( s' y7 C
CDE. |