Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Eclipse Collections Categorically: Level up your programming game
this week in the
Open Source Projects
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Java in General
Object assignments
jose chiramal
Ranch Hand
Posts: 266
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
class Test7 { int a; int b; Test7(int a, int b) { this.a=a; this.b=b; } public static void main(String[] arguments) { int a = 1,b=2; Test7 t1 = new Test7(a,b); int a1 = 3,b1=4; Test7 t2 = new Test7(a1,b1); System.out.println("t1: " + t1.a + ", " + t1.b); System.out.println("t2: " + t2.a + ", " + t2.b); System.out.println("t1 equals t2 ???" + t1.equals(t2)); System.out.println("t1 == t2 ???" + (t1==t2)); t1=t2; t2.a = 100; t2.b = 100; System.out.println("t1: " + t1.a + ", " + t1.b); // am changing only the value for t2, why does the value for t1 also change ? System.out.println("t2: " + t2.a + ", " + t2.b); System.out.println("t1 equals t2 ???" + t1.equals(t2)); System.out.println("t1 == t2 ???" + (t1==t2)); } }
Manish Singh
Ranch Hand
Posts: 160
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Because after t1=t2; both these variables refer to the same object
Get out of my mind! Look! A tiny ad!
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Please Explain (Hashcode)
Please Explain
Interface...
equal() and ==
Strings
More...