-
-
Save idusortus/9201318 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GrowingUp | |
{ | |
public static void main (String args[]) | |
{ | |
Infant newBorn = new Infant("Conrad"); | |
System.out.println("\nHere is what an Infant can do:"); | |
newBorn.crawl(); | |
Child aChild = new Child("Bryce"); | |
System.out.println("\nHere is what a Child can do:"); | |
aChild.crawl(); | |
aChild.walk(); | |
aChild.throwTantrum(); | |
Adolescent aTeenager = new Adolescent("Alex"); | |
System.out.println("\nHere is what an Adolescent can do:"); | |
aTeenager.crawl(); | |
aTeenager.walk(); | |
aTeenager.throwTantrum(); | |
aTeenager.run(); | |
aTeenager.begForMoney(); | |
Adult anAdult = new Adult("Samuel"); | |
System.out.println("\nHere is what an Adult can do:"); | |
anAdult.crawl(); | |
anAdult.walk(); | |
anAdult.throwTantrum(); | |
anAdult.run(); | |
anAdult.begForMoney(); | |
anAdult.goToWork(); | |
anAdult.payBills(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Infant { | |
private String name; | |
public Infant(String n) | |
{ | |
this.name = n; | |
} | |
public String getName() | |
{ | |
return this.name; | |
} | |
public void crawl() | |
{ | |
System.out.printf("Hello! My name is %s and I can crawl!\n", this.getName()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Child extends Infant | |
{ | |
public Child (String name) | |
{ | |
super(name); | |
} | |
public void walk() | |
{ | |
System.out.printf("Hello! My name is %s and I can walk!\n", this.getName()); | |
} | |
public void throwTantrum() | |
{ | |
System.out.printf("Hello! My name is %s and I can throw a tantrum!\n", this.getName()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Adolescent extends Child | |
{ | |
public Adolescent(String name) | |
{ | |
super(name); | |
} | |
public void run() | |
{ | |
System.out.printf("Hello! My name is %s and I can run!\n", this.getName()); | |
} | |
public void begForMoney() | |
{ | |
System.out.printf("Hello! My name is %s and I can beg for money!\n", this.getName()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Adult extends Adolescent | |
{ | |
public Adult(String name) | |
{ | |
super(name); | |
} | |
public void goToWork() | |
{ | |
System.out.printf("Hello! My name is %s and I can go to work.\n", this.getName()); | |
} | |
public void payBills() | |
{ | |
System.out.printf("Hello! My name is %s and can pay bills!\n", this.getName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment