Java Articles

Submit Article
Home » Articles » Java » OperatorsRSS Feeds

Class and Object Operators

Posted By: Benjamin Bouchard     Category: Java     Views: 15459

This article lists and explains class and object operators available in java.

Below are the class and object operators available in java.

Class and Object operators



 a instance of b

Class text operator - The first operand must be an object reference. b is the name of a class or interface. If a is an instance of type b or a subclass of b, then true returned. If a is an instance of interface type b or a sub-interface, then true is returned. Otherwise, false is returned. 

 new a(args)

Class instantiation - Create an instance of class a using constructor a(args). 


Class member access - Access a method or field of a class or object :   o.f - field access for object o.  o.m() - method access for object o. 

 ( )

Method invocation - Parentheses after a method name invokes (i.e. calls) the code for the method, e.g.  o.m(),   o.m(x,y) 


Object cast - Treat an object as the type of class or interface a:  a a1=(a)a2;  Treat a2 as an instance of class or interface a. 


String concatenation - This binary operator will concatenate one string to another. E.g.  String str1 = "abc";  String str2 = "def";  String str3 = str1 + str2; results in str3 holding "abcdef".

For mixed operands, if either a or b in (a + b) is a string, concatenation to a string will occur. Primitives will be converted to strings and the toString() methods of objects will be called. (This is the only case of operator overloading in Java.)

The equivalence operator "+=" will also perform string concatenation. 

 [ ]

Array element access - In Java, arrays are classes. However, the bracket operators work essentially the same as in the C/C++.

To access a given element of an array, place the number of the element as an int value (long values cannot be used in Java arrays) into the brackets, e.g.

float a = b[3];  int n = 5;  char c=c[n];

where b is a float array and c is a char array. 


Didn't find what you were looking for? Find more on Class and Object Operators Or get search suggestion and latest updates.

Benjamin Bouchard
Benjamin Bouchard author of Class and Object Operators is from Montreal, Canada.
View All Articles

Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

No Comment Found, Be the First to post comment!