Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active May 30, 2022 17:15
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 mcsee/9f0082db40c2ab590b2b6ea9702bbb22 to your computer and use it in GitHub Desktop.
Save mcsee/9f0082db40c2ab590b2b6ea9702bbb22 to your computer and use it in GitHub Desktop.
abstract public class Shape{
abstract public int area();
}
public final class Rectangle extends Shape {
int length;
int width;
public Rectangle(int length, int width) {
length = length;
width = width;
}
public int area() {
return length * width;
}
}
public final class Square extends Shape {
int size;
public Square(int size) {
size = size;
}
public int area() {
return size * size;
}
}
public final class Box {
Square shape;
public Box(int size) {
shape = new Square(size);
}
public int area() {
return shape.area();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment