Created
May 27, 2017 16:31
-
-
Save IEnoobong/3c6797931b34090fa01cd4256e6de535 to your computer and use it in GitHub Desktop.
Learning Classes and Objects at ALC 4.0
This file contains 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
/** | |
* | |
* @author ienoobong | |
*/ | |
public class Animal { | |
private int hands; | |
private int legs; | |
private int eyes; | |
public Animal (int hands, int legs, int eyes){ | |
} | |
public void walk(int legs){ | |
} | |
public void see (int eyes){ | |
} | |
public String see (int eyes, boolean open){ | |
if ( eyes >= 1 && open){ | |
return "Boys"; | |
} | |
return "nothing"; | |
} | |
} |
This file contains 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
/** | |
* | |
* @author ienoobong | |
*/ | |
public class Demo1 { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
Monkey monkey = new Monkey(1, 3, 4); | |
System.out.println("I see " + monkey.see(2, false)); | |
monkey.eat("Rice"); | |
} |
This file contains 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
/** | |
* | |
* @author ienoobong | |
*/ | |
public class Monkey extends Animal { | |
public Monkey(int hands, int legs, int eyes) { | |
super(hands, legs, eyes); | |
} | |
public void eat(String food){ | |
if ("banana".equals(food)){ | |
System.out.println("I love this"); | |
} | |
else { | |
System.out.println("You can do better"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment