Skip to content

Instantly share code, notes, and snippets.

@PocasPedro
Created October 30, 2017 18:27
Show Gist options
  • Save PocasPedro/d27e69ae2e893d7d04254f967dee027a to your computer and use it in GitHub Desktop.
Save PocasPedro/d27e69ae2e893d7d04254f967dee027a to your computer and use it in GitHub Desktop.
Java Fundamentals for Kids - Exercise 23
public class NewHumanBeing {
public static class Head {
//Constructor
public Head(){
System.out.println("Creating a Head object");
}
public void move(){
System.out.println("Moving");
}
}
public static class Body {
//Constructor
public Body(){
System.out.println("I have amazing abs!");
}
public void exercising(){
System.out.println("I am exercising");
}
}
public static class Arm {
String armside;
//Constructor
public Arm(String side){
armside = side;
System.out.println("I am the " + armside + " arm!");
}
public void exercising(){
System.out.println("Doing push ups!");
}
}
public static class Leg {
String legside;
//Constructor
public Leg(String side){
legside = side;
System.out.println("I am the " + legside + " leg!");
}
public void exercising(){
System.out.println("Doing skipping!");
}
}
public static void main(String[] args) {
System.out.println("Using Multiple class in the same example");
final Head head = new Head();
final Body body = new Body();
final Arm[] arms = new Arm[2];
arms[0] = new Arm("Right");
arms[1] = new Arm("Left");
final Leg[] legs = new Leg[2];
legs[0] = new Leg("Right");
legs[1] = new Leg("Left");
head.move();
body.exercising();
arms[0].exercising();
arms[1].exercising();
legs[0].exercising();
legs[1].exercising();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment