Skip to content

Commit 20e5297

Browse files
committed
Migrate Reflection code to Core-Java module
1 parent 6bd09ce commit 20e5297

7 files changed

Lines changed: 429 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.baeldung.java.reflection;
2+
3+
public abstract class Animal implements Eating {
4+
5+
public static final String CATEGORY = "domestic";
6+
7+
private String name;
8+
9+
public Animal(String name) {
10+
this.name = name;
11+
}
12+
13+
public String getName() {
14+
return name;
15+
}
16+
17+
public void setName(String name) {
18+
this.name = name;
19+
}
20+
21+
public String makeSound() {
22+
return getSound();
23+
}
24+
25+
protected abstract String getSound();
26+
27+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.baeldung.java.reflection;
2+
3+
public class Bird extends Animal {
4+
private boolean walks;
5+
6+
public Bird() {
7+
super("bird");
8+
}
9+
10+
public Bird(String name, boolean walks) {
11+
super(name);
12+
setWalks(walks);
13+
}
14+
15+
public Bird(String name) {
16+
super(name);
17+
}
18+
19+
@Override
20+
public String eats() {
21+
return "grains";
22+
}
23+
24+
@Override
25+
protected String getSound() {
26+
return "chaps";
27+
}
28+
29+
public boolean walks() {
30+
return walks;
31+
}
32+
33+
public void setWalks(boolean walks) {
34+
this.walks = walks;
35+
}
36+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.java.reflection;
2+
3+
public interface Eating {
4+
String eats();
5+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.baeldung.java.reflection;
2+
3+
public class Goat extends Animal implements Locomotion {
4+
5+
public Goat(String name) {
6+
super(name);
7+
}
8+
9+
@Override
10+
protected String getSound() {
11+
return "bleat";
12+
}
13+
14+
@Override
15+
public String getLocomotion() {
16+
return "walks";
17+
}
18+
19+
@Override
20+
public String eats() {
21+
return "grass";
22+
}
23+
24+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.java.reflection;
2+
3+
public interface Locomotion {
4+
String getLocomotion();
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.baeldung.java.reflection;
2+
3+
public class Person {
4+
private String name;
5+
private int age;
6+
}

0 commit comments

Comments
 (0)