CIS 3020 Part 5
Jump to navigation
Jump to search
Contents
Messy Example 1
Code
ass Mess1 { public static void main (String[] arg) { int d; d=10; System.out.println(d); Ex1 g; g=new Ex1(); g.a(d); System.out.println(d); } } class Ex1 { int p; Ex1() { p=0; } public void a (int p) { this.b(p); this.printVals(p); this.b(this.p); } private void b (int q) { this.printVals(q); } private void printVals(int r) { System.out.println(r); } }
Output
10 10 10 0 10
Messy Example 2
Code
class Mess2 { public static void main (String[] arg) { int d,e; d=4; e=6; System.out.println(d + " " + e); Ex2 g = new Ex2(); g.a(d,e); System.out.println(d + " " + e); } } class Ex2 { int p; Ex2() { p=3; } public void a (int p, int r) { this.b(r,p); this.printVals(p,r); this.b(this.p,r); } private void b (int p, int r) { this.printVals(p,r); this.printVals(this.p,r); } private void printVals(int p, int r) { System.out.println(p + " " + r); } }
Output
4 6 6 4 3 4 4 6 6 3 3 3 4 6
Messy Example 3
Code
class Mess3 { public static void main (String[] arg) { int d,e; d=4; e=6; System.out.println(d + " " + e); Ex3 g = new Ex3(); g.a(d,e); System.out.println(d + " " + e); } } class Ex3 { int p; Ex3() { p=3; } public void a (int p, int r) { this.b(r,p); this.printVals(p,r); this.b(r,this.p); } private void b (int p, int r) { this.printVals(r, this.p); c(p,r); c(this.p, r); } void c(int r, int p) { this.printVals(p,r); } private void printVals(int p, int r) { System.out.println(p + " " + r); } }