File tree Expand file tree Collapse file tree
main/java/com/baeldung/java/reflection
test/java/com/baeldung/java/reflection Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .java .reflection ;
2+
3+ public interface Eating {
4+ String eats ();
5+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .java .reflection ;
2+
3+ public interface Locomotion {
4+ String getLocomotion ();
5+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .java .reflection ;
2+
3+ public class Person {
4+ private String name ;
5+ private int age ;
6+ }
You can’t perform that action at this time.
0 commit comments