Java other special Operators

Java other special Operators

The dot (.) operator is used to select members of a class or object instance:
...
int i = myObject.length;  //Retrieve the value of an instance variable
                         //(of an object) or a static variable (of a class).
myObject.someMethod( );   //A method to be invoked on an object or class
...
  • The new operator is used to create objects out of a class:
    ...
    Object o = new Object( );          // o has reference to new object 
                                       // of Object type (class)
    int hours = new Date().getHours(); // create a new object and invoke a 
                                       // method in it without assigning the object 
    ...
    The instanceof operator is used to test whether an object is an instance of a class:
    ...
    Boolean b;
    String str = "foo";
    b = ( str instanceof String ); // true, str is a String
    b = ( str instanceof Object ); // also true, as String is an Object
    b = ( str instanceof Date );   // false, str is not a Date or subclass
                                   // of Date
    ...
  • © 2010 by Finnesand Data. All rights reserved.
    This site aims to provide FREE programming training and technics.
    Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
    The risk of using this web-site pages or any program codes from this website is entirely at the individual user.