Create an abstract class called Aqualife. Aqualife has the following attributes
ID: 3621841 • Letter: C
Question
Create an abstract class called Aqualife.
Aqualife has the following attributes ; name, age, lake-fish or ocean-fish,
Aqualife defines 2 abstract methods called eat() and procreates().
A third concrete method called Breathes() displays that ‘These creatures breathe from gills.’
Subclasses of Aqualife are fish, and whale.
Fish has an attribute which stores whether the fish is a herbivore or a carnivore.
The eat method checks whether herbivore and prints ‘ This fish eats veggies’ for herbivores and prints ‘This fish eats other fish’ for carnivores.
The procreates method prints ‘Fish lay eggs’
Whale has an attribute that specifies whether the whale is a blue whale or a killer whale. If the whale is a blue whale, it eats veggies, if it is a killer whale it eats meat.
The procreates method prints that whales are mammals.
Override the breathes method from the parent class. This method must print ‘These mammals breathe above water’.
Explanation / Answer
// save as test.java and run
// loaded with all features that u wanted and tested toooo.....
abstract class Aqualife
{
String name;
int age;
int lake_fish;
int ocean_fish;
abstract void eat();
abstract void procreates();
void Breathes()
{
System.out.println("These creatures breathe from gills.");
}
}
class Fish extends Aqualife
{
Fish()
{
}
Fish(String a)
{
name = a;
}
void eat()
{
if(name.equals("herbivore"))
System.out.println("This fish eats veggies");
if(name.equals("carnivore"))
System.out.println("This fish eats other fish");
}
void procreates()
{
System.out.println("Fish lay eggs’");
}
}
class Whale extends Aqualife
{
Whale()
{
}
Whale(String s)
{
name = s;
}
void eat()
{
if(name.equals("blue"))
System.out.println("it eats veggies");
if(name.equals("killer"))
System.out.println("it eats meat.");
}
void procreates()
{
System.out.println("whales are mammals.");
}
void Breathes()
{
System.out.println("These mammals breathe above water");
}
}
public class test
{
public static void main(String[] a)
{
Fish f1 = new Fish("herbivore");
f1.eat();
f1.procreates();
f1.Breathes();
Fish f2 = new Fish("carnivore");
f2.eat();
Whale w1 = new Whale("blue");
w1.eat();
w1.procreates();
w1.Breathes();
Whale w2 = new Whale("killer");
w2.eat();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.