







Ein Beispiel von unserem Freund dem Fish, aber was ist es für ein Fischlein?
class Fish extends Pet{
int currentDepth=0;
int tooDeep=0;
public String say(String something){
return "Dummy, don't Ya know that fish do NOT talk?!";
}
public int dive (int howDeep){
currentDepth = currentDepth + howDeep;
tooDeep = currentDepth - 100;
if (currentDepth > 100){
System.out.println("I'm just a little fish and can't dive " +
"like a Shark " + currentDepth + " feet, you PappNose!");
System.out.println("That is " + tooDeep + " feet too deep!");
}else{
System.out.println("Diving for " + howDeep + " feet.");
System.out.println("I'm at " + currentDepth +
" feet below sea level.");
}
return currentDepth;
}
}
public class FishMaster {
public static void main(String[] args) {
String fishReaction;
String sharkReaction;
Fish myGuppy = new Fish();
myGuppy.dive(2);
myGuppy.dive(3);
System.out.println("");
System.out.println("A little fish likes to dive like a shark!");
myGuppy.dive(45);
myGuppy.dive(45);
myGuppy.dive(6);
Shark myShark = new Shark(); /*Something you should know about sharks*/
System.out.println("");
System.out.println("A shark CAN dive like a shark!");
myShark.dive(50);
myShark.dive(45);
myShark.dive(6);
fishReaction = myGuppy.say("Hello I'am a fish!");
sharkReaction = myShark.say("Hello I'am a shark!");
System.out.println("");
System.out.println(fishReaction);
System.out.println(sharkReaction);
System.out.println("");
myGuppy.sleep();
myShark.sleep();
}
}
public class Shark extends Fish{ /*Something you should know about sharks*/
int currentDepth=0;
public String say(String something){
return "Dear my friend, a shark can not talk either!";
}
public int dive (int howDeep){
currentDepth = currentDepth + howDeep;
System.out.println("Diving for " + howDeep + " feet.");
System.out.println("I'm at " + currentDepth + " feet below sea level.");
return currentDepth;
}
public void sleep(){
System.out.println("Sharks do not sleep!");
System.out.println("");
}
}