public class AbstractTest
{
public static void main(String[] args)
{
Cat cat = new Cat("Kitty", "Angora");
Robin bird = new Robin("Rockin");
System.out.println("For the cat:");
System.out.print("This is: \n"); cat.describe();
System.out.print("Sound: \n"); cat.sound();
System.out.print("Sleeping: \n"); cat.sleep();
System.out.print("Moving: \n"); cat.move();
System.out.println("\n");
System.out.println("For the robin:");
System.out.print("This is: \n"); bird.describe();
System.out.print("Sound: \n"); bird.sound();
System.out.print("Sleeping: \n"); bird.sleep();
System.out.print("Moving: \n"); bird.move();
System.out.print("\n");
System.out.println("End of program.");
}
}
public abstract class Animal
{
String type;
public Animal(String type)
{
this.type = type;
}
public abstract String describe();
public abstract String sound();
public abstract String sleep();
public abstract String move();
}
public abstract class Bird extends Animal
{
protected String breed;
public Bird()
{
super("Bird");
}
public abstract String move();
}
public class Cat extends Animal
{
private String name;
protected String breed;
public Cat(String name, String breed)
{
super("Cat");
this.name=name;
this.breed=breed;
}
public Cat()
{
super("Cat");
}
public String describe()
{
return new String(",a breed of Cat called");
}
public String sound()
{
return new String("Meow");
}
public String sleep()
{
return new String("Kitty is having purfect dreams!");
}
public String move()
{
return new String("This little Kitty moves fast!");
}
}
public class Robin extends Bird
{
private String name;
protected String breed;
public Robin(String name)
{
}
public String describe()
{
return new String(",a breed of Bird called");
}
public String sound()
{
return new String("Tweet Tweet!");
}
public String sleep()
{
return new String("Rockin the Robin Sleeps with one eye open for the cat!");
}
public String move()
{
return new String("This Robin flies up and away!");
}
}
[edit]: code tags PB
This post has been edited by PennyBoki: 02 October 2007 - 06:54 PM

New Topic/Question
Reply




MultiQuote






|