File tree 4 files changed +47
-0
lines changed
RandomProblems/src/learnHeadFirstJava
4 files changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ package learnHeadFirstJava ;
2
+
3
+
4
+ public class Animal extends Creature {
5
+
6
+ public Animal () {
7
+ System .out .println ("Animal constructor is getting called!" );
8
+ }
9
+ }
10
+
11
+
Original file line number Diff line number Diff line change
1
+ package learnHeadFirstJava ;
2
+
3
+ public abstract class Creature {
4
+
5
+ public Creature () {
6
+ System .out .println ("Creature constructor is getting called!" );
7
+ }
8
+
9
+ }
Original file line number Diff line number Diff line change
1
+ package learnHeadFirstJava ;
2
+
3
+ public class Dog extends Pet {
4
+
5
+ public Dog () {
6
+ System .out .println ("Dog constructor is getting called!" );
7
+ }
8
+
9
+ public static void main (String [] args ) {
10
+ Dog myDog = new Dog ();
11
+ System .out
12
+ .println ("\n This is really calling as the book stated and as I expected,\n "
13
+ + "each method gets put onto the stack, up to the end of the inheritance "
14
+ + "tree, then the root constructor is called, "
15
+ + "then down to the bottom subclass's constructor is called!\n Nice!\n Program ended." );
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ package learnHeadFirstJava ;
2
+
3
+
4
+ public class Pet extends Animal {
5
+
6
+ public Pet () {
7
+ System .out .println ("Pet constructor is getting called!" );
8
+ }
9
+
10
+ }
You can’t perform that action at this time.
0 commit comments