Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ANIMAL:
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package inheritance;
- /**
- *
- * @author Arthur
- */
- public class Animal {
- private String name;
- private int brain;
- private int body;
- private int size;
- private int weight;
- public Animal(String name, int brain, int body, int size, int weight) {
- this.name = name;
- this.brain = brain;
- this.body = body;
- this.size = size;
- this.weight = weight;
- }
- public void eat() {
- System.out.println("Animal.eat() called");
- }
- public void move(int speed) {
- System.out.println("Animal.move() called. Animal is moving at " + speed);
- }
- public String getName() {
- return name;
- }
- public int getBrain() {
- return brain;
- }
- public int getBody() {
- return body;
- }
- public int getSize() {
- return size;
- }
- public int getWeight() {
- return weight;
- }
- }
- DOG:
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package inheritance;
- /**
- *
- * @author Arthur
- */
- public class Dog extends Animal {
- private int eyes;
- private int legs;
- private int tail;
- private int teeth;
- private String coat;
- public Dog(String name, int size, int weight, int eyes, int legs, int tail, int teeth, String coat) {
- super(name, 1, 1, size, weight);
- this.eyes = eyes;
- this.legs = legs;
- this.tail = tail;
- this.teeth = teeth;
- this.coat = coat;
- }
- private void chew() {
- System.out.println("Dog.chew() called");
- }
- @Override
- public void eat() {
- System.out.println("Dog.eat() called");
- chew();
- super.eat(); //To change body of generated methods, choose Tools | Templates.
- }
- public void walk() {
- System.out.println("Dog.walk() called");
- move(5);
- }
- public void run() {
- System.out.println("Dog.run() called");
- move(10);
- }
- private void moveLegs(int speed) {
- System.out.println("Dog.moveLegs() called");
- }
- @Override
- public void move(int speed) {
- System.out.println("Dog.move() called");
- super.move(speed);
- moveLegs(speed);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement