|
|
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
The?:operator is a conditional operator that is short-hand for anif-elsestatement:Theop1 ? op2 : op3?:operator returnsop2ifop1is true or returnsop3ifop1is false.For information about the
if-elsestatement, refer to The if/else Statements.
You use square brackets to declare arrays, to create arrays, and to access a particular element in an array. Here's an example of an array declaration:The previous code declares an array that can hold ten floating point numbers. Here's how you would access the 7th item in that array:float[] arrayOfFloats = new float[10];Note that array indices begin at 0. ArraysarrayOfFloats[6];contains more information about arrays.
The dot (.) operator accesses instance members of an object or class members of a class. You will learn more about this operator in the next lesson, Classes, Interfaces, and Packages.
When declaring or calling a method, you list the method's arguments between(and). You can specify an empty argument list by using()with nothing between them. The next lesson, Classes, Interfaces, and Packages, covers methods.
[PENDING: cover casting (implicit as well as explicit) here]
You use the new operator to create a new object or a new array. Here's an example of creating a newIntegerobject from theIntegerclass in thejava.langpackage:For a detailed explanation about creating objects using a statement like the previous, refer to Creating ObjectsInteger anInteger = new Integer(10);in the next lesson. To learn about creating arrays, refer to Arrays
.
Theinstanceofoperator tests whether its first operand is an instance of its second.op1 instanceof op2op1must be the name of an object andop2must be the name of a class. An object is considered to be an instance of a class if that object directly or indirectly descends from that class.
|
|
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |