File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Operator and Assignment Mock Question

R .sourav nayak
Ranch Hand

Joined: May 14, 2006
Posts: 67
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();
public void ww(){
Base b = new Base();
Base b2 = new Base();
b.iAge = 10;
b2.iAge = 20;
Integer iw = new Integer(b.iAge);

public static void col(Object o){
Integer iw = (Integer) o;

thanks in advance.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2398
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: 1710
Hi Saurav,

You may try the following code:

Srinivas Kumar
Ranch Hand

Joined: Jul 14, 2005
Posts: 52
Absolutely a good question with a trap ;-)
I agree. Here's the link:
subject: Operator and Assignment Mock Question
It's not a secret anymore!