java help: i need to write a code. This was the problem given to me, ignore the
ID: 3819725 • Letter: J
Question
java help:
i need to write a code. This was the problem given to me, ignore the first sentence.
Explanation / Answer
public class Animal {
private int height;
private int weight;
public Animal(int h ,int w){
this.setHeight(h);
this.setWeight(w);
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
}
class Bird extends Animal{
private String type;
public Bird(int h ,int w, String t){
super(h,w);
this.type =t;
}
boolean canFly(){
if(type.equalsIgnoreCase("Penguin"))
return false;
//We can add more if
return true;
}
}
class Fish extends Animal {
private String type;
public Fish(int h ,int w, String t){
super(h,w);
this.type =t;
}
boolean needAir(){
if(type.equalsIgnoreCase("Whale"))
return true;
//We can add more if
return false;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.