Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package week3training;
- public class Day17B {
- public static void main(String[] args) {
- Pig callPig = new Pig();
- System.out.println("What can a pig do?");
- callPig.makeSounds();
- callPig.movement();
- callPig.eat();
- }
- }
- class Animal {
- public void makeSounds() {
- System.out.println("Most animals make sounds");
- }
- public void movement() {
- System.out.println("It walks on all fours");
- }
- public void eat() {
- System.out.println("Its an omnivore");
- }
- }
- class Pig extends Animal {
- @Override
- public void makeSounds() {
- System.out.println("A pig goes oink oink");
- }
- }
- //---------------------------------------------------------------------------
- package week3training;
- public class Day17C {
- public static void main(String[] args) {
- PlantProduce callPlant = new PlantProduce("green","normal");
- callPlant.foodColor();
- callPlant.foodTaste();
- Ampalaya callAmpalaya = new Ampalaya();
- callAmpalaya.foodColor();
- callAmpalaya.foodTaste();
- Kiwi callKiwi = new Kiwi();
- callKiwi.foodColor();
- callKiwi.foodTaste();
- }
- }
- class PlantProduce {
- String produceName = "food";
- String color;
- String taste;
- public PlantProduce(String color, String taste) {
- this.color = color;
- this.taste = taste;
- }
- public void foodColor() {
- System.out.println(String.format("The %s have a color of %s",produceName, color));
- }
- public void foodTaste() {
- System.out.println(String.format("The %s taste %s",produceName, taste));
- }
- }
- class Ampalaya extends PlantProduce {
- public Ampalaya() {
- super("green", "bitter");
- this.produceName = "Bitter melon";
- }
- }
- class Kiwi extends PlantProduce {
- public Kiwi() {
- super("brown", "salty");
- this.produceName = "Kiwi";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement