File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""== operator checks for object references" Watch ""== operator checks for object references" New topic

"== operator checks for object references

Ashish Hareet
Ranch Hand

Joined: Jul 14, 2001
Posts: 375
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";
if(ob.xtc_var == obj.xtc_var)

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"

Joined: Sep 29, 2000
Posts: 8521

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: "== operator checks for object references
It's not a secret anymore!