Skip to content

Instantly share code, notes, and snippets.

@idusortus
Forked from anonymous/Adolescent.java
Last active August 29, 2015 13:56
Show Gist options
  • Save idusortus/9201318 to your computer and use it in GitHub Desktop.
Save idusortus/9201318 to your computer and use it in GitHub Desktop.
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();
}
}
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());
}
}
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());
}
}
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());
}
}
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