Skip to content

Instantly share code, notes, and snippets.

@sivabudh
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivabudh/9202632 to your computer and use it in GitHub Desktop.
Save sivabudh/9202632 to your computer and use it in GitHub Desktop.
class Object2 {
int y, x, z;
Object2 () { // constructor
y = 5; x = 2; z = 1;
}
public int doAnother() {
y += 1;
return y;
}
}
class Untitled {
public void doSomething( Object2 obj2 ){
int newY = obj2.doAnother();
System.out.println(newY);
}
public static void main(String[] args) {
Untitled u = new Untitled();
Object2 obj2 = new Object2();
Object2 obj3 = new Object2();
u.doSomething(obj2);
u.doSomething(obj2);
u.doSomething(obj3);
}
}
@sivabudh
Copy link
Author

Output is:

6
7
6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment