• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"== operator checks for object references

 
Ashish Hareet
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not exactly what u expect but i finally understand overloading methods , static members & object references . Might aswell post it for u lot to see .
Put the following codes in their individual files & well compile 'em .Run 'em n see what happens !!! U can run 'em individually aswell .

class XTC{//this is code one
static String xtc_var = "same for all";
public static String main(){
xtc_var = "xtc_var changed";
return "Exiting main() with String sign.";
}
public static void main(String[]ka){
System.out.println("Exiting main() with std. sign.");
xtc_var = "Am I Evil";
}
};
class Voodoo{//this is code two
public static void main(String []ka){
System.out.println("xtc_var is "+XTC.xtc_var);
XTC ob = new XTC();
XTC obj = new XTC();
String str[] = new String[1];
str[0] = "Does it matter";
System.out.println(XTC.main());
XTC.main(str);
if(ob.xtc_var == obj.xtc_var)
System.out.println(ob.xtc_var);
}
};

Hint-
Methods can be overloaded so what if it is main()
All instances of a class share the same static variables
== operator compares two object refernces

Here's the o/p-
---------- java ----------
xtc_var is same for all
Exiting main() with String sign.
Exiting main() with std. sign.
Am I Evil
Normal Termination
Output completed (3 sec consumed).
Just give it a little thought , u will get it .
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic