repl.it
@bbenefield89/

Composition vs Inheritance

Java

No description

fork
loading
Files
  • Main.java
  • jdt.ls-java-project
  • Dog.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Main {
  public static void main(String[] args) {
    Dog dog = new Dog(
      new Object() { String name = "Fluffy"; }
    );

    Object foo = new Object() {
      String name = "Fluffy";

      public String getName() {
        return name;
      }
    };

    System.out.print(foo.getName());
    
    dog.speak();
  }
}
?