Browse over 20 million
homework answers & study documents

Computer Science

Java programmers can use class hierarchies for the purposes of inheritance.

Type

Homework

Rating

Showing Page:
1/6
/**
* Created by e7006722 on 4/07/2014.
*/
public class Animal {
private String name;
@Override
public String toString() {
return "Animal{" +
"name='" + name + '\'' +
'}';
}
public Animal() {
}
public Animal(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
/**
* Created by e7006722 on 4/07/2014.
*/
public class Mammal extends Animal {
private String habitat;
public Mammal() {
}
public Mammal(String habitat) {
this.habitat = habitat;
}
public Mammal(String name, String habitat) {
super(name);
this.habitat = habitat;
}
@Override
public String toString() {
return "Mammal{" +
"habitat='" + habitat + '\'' +
'}';
}
public String getHabitat() {
return habitat;
}

Sign up to view the full document!

lock_open Sign Up
public void setHabitat(String habitat) {
this.habitat = habitat;
}
public void nurse()
{
System.out.println("Called the Mammal.nurse method");
}
}
/**
* Created by e7006722 on 4/07/2014.
*/
public class Oviparous extends Animal {
private String dwelling;
@Override
public String toString() {
return "Oviparous{" +
"dwelling='" + dwelling + '\'' +
'}';
}
public Oviparous() {
}
public Oviparous(String dwelling) {
this.dwelling = dwelling;
}
public Oviparous(String name, String dwelling) {
super(name);
this.dwelling = dwelling;
}
public String getDwelling() {
return dwelling;
}
public void setDwelling(String dwelling) {
this.dwelling = dwelling;
}
public void layEggs()
{
System.out.println("Called the Oviparous.layEggs method");
}
}
/**
* Created by e7006722 on 4/07/2014.
*/
public class Bat extends Mammal {
private String eatingHabit;
@Override

Sign up to view the full document!

lock_open Sign Up

Sign up to view the full document!

lock_open Sign Up

Anonymous
Just what I needed. This document gave me a good start on tailoring my own answer.

Anonymous
Documents were of surprisingly high quality, and not like anything I’ve seen on other sites. Very impressed at how even a university level assignment was handled.

Anonymous
Never disappoints. Thanks for being awesome!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4