permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Operator and Assignment Mock Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Operator and Assignment Mock Question" Watch "Operator and Assignment Mock Question" New topic
Author

Operator and Assignment Mock Question

R .sourav nayak
Ranch Hand

Joined: May 14, 2006
Posts: 67
hi,
could someone explain me how the output of the following program is 2020

class Base{
public static int iAge;

}
public class CSturt{
public static void main(String argv[]){
CSturt cs = new CSturt();
cs.ww();
}
public void ww(){
Base b = new Base();
Base b2 = new Base();
b.iAge = 10;
b2.iAge = 20;
System.out.print(b.iAge);
Integer iw = new Integer(b.iAge);
col(iw);


}
public static void col(Object o){
Integer iw = (Integer) o;
System.out.print(iw.intValue());
}
}



thanks in advance.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Note that iAge is a static variable.

So even though you have two instances of the class, using either instance to access iAge accesses the same variable.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Hi Saurav,

You may try the following code:



cmbhatt
Srinivas Kumar
Ranch Hand

Joined: Jul 14, 2005
Posts: 52
Absolutely a good question with a trap ;-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Operator and Assignment Mock Question
 
Similar Threads
explain the output
Q from Marcus Green Exam
Doubt on Variable Intialization
doubt in marcus green
Static Method