Posted by: ahmedashfaque | February 1, 2015

object oriented programming puzzle


I have a small puzzle for you. I have a piece of code where I create objects from a class and do some assignments. Please find out solution of the computation done in this code. Also find out the reason for the solution.

public class a {

int count = 0;

}

public class b{

public static void main (String[] args){

a e1 = new a();

a e2 = new a();

int x = 4;

e1.count = x;

e2=e1;

e2.count = e2.count + 1;

system.out.println(e1.count+e2.count);

}

}

Tomorrow I will provide the solution with explanation.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: