Skip to content

Instantly share code, notes, and snippets.

@lucamolteni
Created November 21, 2019 08:58
Show Gist options
  • Save lucamolteni/725f5bac7778ec70693681bf8905cb7e to your computer and use it in GitHub Desktop.
Save lucamolteni/725f5bac7778ec70693681bf8905cb7e to your computer and use it in GitHub Desktop.
class Scratch {
public static void main(String[] args) {
SumOOP sumOOP = new SumOOP(2, 3);
System.out.println("sumOOP = " + sumOOP.compute());
SumNoOOP sumNoOOP = new SumNoOOP(2, 3);
int sumNoOOp = sumNoOOP.getA() + sumNoOOP.getB();
System.out.println("sumNoOOP = " + sumNoOOP);
}
static class SumOOP {
int a;
int b;
public SumOOP(int a, int b) {
this.a = a;
this.b = b;
}
int compute() { return a + b; }
}
static class SumNoOOP {
int a;
int b;
public SumNoOOP(int a, int b) {
this.a = a;
this.b = b;
}
public int getA() {
return a;
}
public void setA(int a) {
this.a = a;
}
public int getB() {
return b;
}
public void setB(int b) {
this.b = b;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment