Java Reference
In-Depth Information
tabEvent [1]= e2 ;
tabEvent [2]= e3 ;
System . out . print (
"Oldest person::"
);
Display(oldest(tabEvent)) ;
}
}
Running this program yields the following console output:
Birthday Julien: 26 June 2003
Oldest person::Birthday Me: 23 June 1971
5.5 Objects with array members
Records of objects may also contain arrays. These arrays should always be built
by the object constructor as follows:
new Type[sizeArrayExpression]
.Thus
it is not necessary at compile time to know the array sizes provided that at
run time the expression
sizeArrayExpression
can be evaluated to an integer
value. In the chapter introduction, we mentioned that for student objects, we
would like to store their grades using an array of
double
. Another example is
a data-structure for polynomials that may be created using the following class:
class Polynome{
int degree;
double [ ] coefficients; // Array declaration
};
5.6 The standardized
String
objects
5.6.1 Declaring and assigning
String
variables
In Java, a string of characters is manipulated with an object of type
String
.
The
String
type does
not
belong to the primitive types (
boolean
,
int
,
double
,
etc.), but is rather a non-primitive object type. Therefore, a variable of type
String
is a reference to that object in the global memory. Thus for the same
reasons as for the case of integers, the following
badSwap
function will not
swap the string variables since once the function is executed the values of
p
and
q
(that is, the respective references) are kept unchanged: Java is pass-
by-value/reference only. For non-primitive types such as arrays, objects and
strings, the stored value is a reference.
static void badSwap(String p, String q)
Search WWH ::
Custom Search