[ Team LiB ] 4 Declarations and Access
Wednesday, January 31st, 2007Page 602
Note: If you are looking for good and quality webspace to host and run your java application check professional java hosting services
Page 602
Note: If you are looking for good and quality webspace to host and run your java application check professional java hosting services
[ Team LiB ] 4 Declarations and Access Control 4.1 (d) In Java, arrays are objects. Each array object has a final field named lengththat stores the size of the array. 4.2 (a) Java allows arrays of length zero. Such an array is passed as an argument to the main() method when a Java program is run without any program arguments. 4.3 (c) The [] notation can be placed both before and after the variable name in an array declaration. Multidimensional arrays are created by constructing arrays that can contain references to other arrays. The expression new int[4][] will create an array of length 4, which can contain references to arrays of int values. The expression new int[4][4] will create the same array, but will in addition create four more arrays, each containing four int values. References to each of these arrays are stored in the first array. The expression int[][4] will not work, because the arrays for the dimensions must be created from left to right. 4.4 (b) and (e) The size of the array cannot be specified as in (b) and (e). The size of the array is given implicitly by the initialization code. The size of the array is never specified in the declaration of an array reference. The size of an array is always associated with the array instance, not the array reference. 4.5 (e) The array declaration is valid and will declare and initialize an array of length 20 containing int values. All the values of the array are initialized to their default value of 0. The for loop will print all the values in the array, that is, it will print 0 twenty times. Page 601
Note: If you are looking for good and quality webspace to host and run your java application check professional java hosting services
Page 599
Hint: If you are looking for very good and affordable webspace to host and run your j2ee hosting application check Sandzak.com j2ee web hosting services
[ Team LiB ] Page 600
Hint: If you are looking for very good and affordable webspace to host and run your j2ee hosting application check Sandzak.com j2ee web hosting services
Page 598
Hint: If you are looking for very good and affordable webspace to host and run your j2ee hosting application check Sandzak.com j2ee web hosting services
Page 597
Note: If you are looking for top 10 and very good webhost to host and run your jsp application check Actions jsp hosting services
[ Team LiB ] 3 Operators and Assignments 3.1 (a) A value of type char can be assigned to a variable of type int. An implicit widening conversion will convert the value to an int. 3.2 (d) An assignment statement is an expression statement. The value of the expression statement is the value of the expression on the right hand side. Since the assignment operator is right associative, the statement a = b = c = 20 is evaluated as follows: (a = (b = (c = 20))). This results in the value 20 being assigned to variable c, then the same value being assigned to variable b and finally to variable a. The program will compile correctly and display 20 when run. 3.3 (c) Strings are objects. The variables a, b, and c are references that can denote such objects. Assigning to a reference only changes the reference value. It does not create a copy of the source object or change the object denoted by the old reference value in the destination reference. In other words, assignment to references only affects which object the destination reference denotes. The reference value of the “cat” object is first assigned to variable a, then to variable b, and later to variable c. The program prints the string denoted by the variable c, which is “cat”. 3.4 (a), (d), and (e) A binary expression with any floating-point operand will be evaluated using floating-point arithmetic. Expressions such as 2/3, where both operands are integers, will use integer arithmetic and evaluate to an integer value. 3.5 (b) The / operator has higher precedence than the + operator. This means that the expression is evaluated as ((1/2) + (3/2) + 0.1). The associativity of the binary operators is from left to right, giving (((1/2) + (3/2)) + 0.1). Integer division results in ((0 + 1) + 0.1) which evaluates to 1.1. Page 595
Note: If you are looking for top 10 and very good webhost to host and run your jsp application check Actions jsp hosting services
Page 596
Note: If you are looking for top 10 and very good webhost to host and run your jsp application check Actions jsp hosting services
[ Team LiB ] Page 594
Note: If you are looking for cheapest and affordable webspace to host and run your servlet application check Astra j2ee hosting services
Page 593
Note: If you are looking for cheapest and affordable webspace to host and run your servlet application check Astra j2ee hosting services