0

Here's the code I tried to run:

abstract class Bird {
  abstract void fly(); 
  abstract void deepDive(); 
  abstract void talk(); 
  abstract void swim(); 
  public String toString() {
    this.talk();  
    this.fly();  
    this.deepDive();  
    this.swim(); 
    return ""; 
  }
}

class Duck extends Bird {
  void fly() 
  {
    System.out.println("I am flying like a Duck.");  
  }
  void deepDive() 
  { 
    System.out.println("I deep dive like a Duck"); 
  } 
  void talk() 
  { 
    System.out.println("Ducks don't talk."); 
  } 
  void swim() 
  { 
    System.out.println("I swim like a Duck.");
  } 
  public String toString() 
  {
    super.toString();  
    return " -- all of this coming from a duck.";
  }
}

class Parrot extends Bird {
  void fly() 
  { 
    System.out.println("I fly like a Parrot."); 
  } 
  void deepDive() 
  { 
    System.out.println("Parrots don't deep dive"); 
  } 
  void talk() 
  { 
    System.out.println("I talk like a Parrot."); 
  } 
  void swim() 
  { 
    System.out.println("Parrots don't swim.");
  }
  public String toString() 
  {
    super.toString();  
    return " -- all of this coming from a parrot.";
  }
}

class Penguin extends Bird 
{
  void fly() 
  {
    System.out.println("Penguins don't fly.");  
  }
  void deepDive()
  {
    System.out.println("Penguins are masters of deep dive.");
  }
  void talk()
  {
    System.out.println("Penguins don't talk.");
  }
  void swim() 
  { 
    System.out.println("I am swimming like a penguin.");
  }
  public String toString() 
  {
    super.toString();  
    return " -- all of this coming from a penguin.";
  }
}

public class BirdCorrection{
  public static void main(String[] args)
  {
    Bird a = new Duck();
    System.out.println(a);
    Bird b = new Penguin();
    System.out.println(b);
    Bird c = new Parrot();
    System.out.println(c);
  }
}

This runs in online compilers, and my professors and TA's say this should run. Rather, I got "Static Error: This class does not have a static void main method accepting String[]" However, it did not run in Dr. Java, tho it does compile. I tried deleting Dr. Java and then the .drjava file, then clean reinstalling, still no dice.

I did move the main to the top, and it ran in DrJava. But both times, the file was indeed named BirdCorrection.

user311302
  • 97
  • 5

0 Answers0