Lets take this example:
class Class
{
String object;
Class ob;
void display()
{
object= object+1;
ob = ob+1;
System.out.println(object +" "+ ob );
}
public static void main (String args[])
{
Class obj = new Class();
obj.display();
}
}
This gives a compile time error : bad operand types for binary operator + first type find ; second type : int. This error points at this line of my code ob = ob+1; .
However, when I eliminate this line, the program executes in a proper manner (printing the String as null1).
Now my question is, that object and ob are both objects of class String and class Class respectively so why/how am I able to add 1 to null value of object and not that of ob?