Jump to content

Programming puzzles


Perakp

Recommended Posts

Ok I wanted to ask a little fast question, but realized the question was too stupid to ask. Might aswell find the answer myself since I got the pseudocode written. To make the topic worthwhile, post any small programming puzzles or problems to test one's programming abilities.

 

I'll go first:

 

In Java I have made my own class, that holds one property. It has a method to set that property and another one to print it to the console.

Consider the following code. What would it print?

Object a = new Object();
a.setProperty(5);
ArrayList<Object> list = new ArrayList<Object>();
list.add(a);

list.get(0).setProperty(6);
a.printProperty();
list.get(0).printProperty();

a.setProperty(4);
a.printProperty();
list.get(0).printProperty();

 

Answer:

[hide]

6

6

4

4

[/hide]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.