Question
Make a file called Main.java , add a class called Main, this is a static class and contains our main method Make an abstract class
Make a file called Main.java , add a class called Main, this is a static class and contains our main method
- Make an abstract class Animals, include
- Private String name
- A constructor that takes an argument name
- A public method getName
- abstract public String behaviour();
- Make a class Mammals that extends Animals, include
- A constuctor that takes an argument name
- An inherited method behaviour that returns " runs on land"
- Make a class Birds that extends Animals, include
- A constuctor that takes an argument name
- An inherited method behaviour that returns " flies in air"
- Make a class Fish that extends Animals, include
- A constuctor that takes an argument name
- An inherited method behaviour that returns " swims in water"
This is the code i have so far:
For Main:
public class Main {
public static void main(String[] args) { // TODO Auto-generated method stub
Birds birds = new Birds ("swallow"); Mammals Mammals = new Mammals ("monkey"); Fish Fish = new Fish ("pike"); System.out.println(swallow.getName() + swallow.behaviour()); System.out.println(Monkey.getName() + Monkey.behaviour()); System.out.println(pike.getName() + pike.behaviour()); }
}
For Animals:
public abstract class Animal{ private String name;
public abstract String behaviour();
public Animal(String name){ this.name = name; } public String getName(){ return this.name; } }
For Mammals:
public class Mammals extends Animal{ public Mammals(String name){ super(name); } public String behavior(){ return "runs on land"; } }
For Birds:
public class Birds extends Animal{ public Birds(String name){ super(name); } public String behavior(){ return "flies in air"; } }
For Fish:
public class Fish extends Animal{ public Fish(String name){ super(name); } public String behavior(){ return "swims in water"; } }
I am stuck at this point can you explain the question in detail and also explain where I am going wrong and where to fix it.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
It looks like youre on the right track with your implementation Lets go through the requirements and make sure everything is implemented correctly 1 M...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started