This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in assigning Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in assigning Objects" Watch "Doubt in assigning Objects" New topic
Author

Doubt in assigning Objects

pramodh somashekara
Ranch Hand

Joined: Jan 30, 2006
Posts: 62
Can anybody explain how m3.m1 is assigned to Ex1.m4 in the following code?

class Ex1 {
Ex1() { }
Ex1(Ex1 m) {
m1 = m;
}
Ex1 m1;

public static void main(String[] args) {
Ex1 m2 = new Ex1();
Ex1 m3 = new Ex1(m2);
m3.go();
Ex1 m4 = m3.m1;
m4.go();
Ex1 m5 = m2.m1;
m5.go();
}

void go() {
System.out.print("hi ");
}
}
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Originally posted by pramodh somashekara:
Can anybody explain how m3.m1 is assigned to Ex1.m4 in the following code?

class Ex1 {
Ex1() { }
Ex1(Ex1 m) {
m1 = m;
}
Ex1 m1;

public static void main(String[] args) {
Ex1 m2 = new Ex1();
Ex1 m3 = new Ex1(m2);
m3.go();
Ex1 m4 = m3.m1;
m4.go();
Ex1 m5 = m2.m1;
m5.go();
}

void go() {
System.out.print("hi ");
}
}


The type of m1 in Ex1 is Ex1. The type of m4 is Ex1.
 
 
subject: Doubt in assigning Objects
 
Similar Threads
explain output
Please Explain
K & B question ???
Exception
explain me this code