Language Families Help

https://www.codecademy.com/courses/learn-java/projects/java-language-families

I need help debugging. Whenever I run my code, I get one error
$ javac Language.java
Language.java:16: error: ‘;’ expected
public void getInfo() {
^
1 error

Here is my code
Language.java

// August 4 2020 
class Language {
  protected String name;
  protected int numSpeakers; 
  protected String regionSpoken; 

  protected String wordOrder; 

  Language(String langName, int speakers, String regions, String wOrder) {
    this.name = langName; 
    this.numSpeakers = speakers; 
    this.regionSpoken = regions; 
    this.wordOrder = wOrder; 
    
    @Override 
    public void getInfo() {
      System.out.println(this.name + " is spoken by " + this.numSpeakers + " people mainly in " + this.regionSpoken + "."); 
      System.out.println("The language spoken follows the order:" + this.wordOrder); 
      }
      }

  public static void main(String[] args) {

  }
  }

Mayan.java

class Mayan extends Language {
  Mayan(String languageName, int speakers) {
    super (languageName, speakers, "Central America", "verb-object-subject"); 


  }
}

SinoTibetan.java

class SinoTibetan extends Language {
  SinoTibetan(String languageName, int speakers) {
    super(languageName, speakers, "Asia", "subject-object-verb"); 
    if (languageName.contains("Chinese")) {
      this.wordOrder = "subject-verb-object"; 

  }
}


}


Help me find my mistake

Language(String langName, int speakers, String regions, String wOrder) {
    this.name = langName; 
    this.numSpeakers = speakers; 
    this.regionSpoken = regions; 
    this.wordOrder = wOrder; 

Do you mean for the constructor class to contain getInfo()'s declaration? I think you’re missing a curly bracket there.

Language.java:16: error: ‘;’ expected
public void getInfo() {

Just for reference, usually the logic of this error comes from a mistake in the code previous to the declaration itself.

Language.java:16 error: method does not override or implement a method from a supertype

/ August 4 2020 
class Language {
  protected String name;
  protected int numSpeakers; 
  protected String regionSpoken; 

  protected String wordOrder; 

  Language(String langName, int speakers, String regions, String wOrder) {
    this.name = langName; 
    this.numSpeakers = speakers; 
    this.regionSpoken = regions; 
    this.wordOrder = wOrder; 
  }
    
    @Override 
    public void getInfo() {
      System.out.println(this.name + " is spoken by " + this.numSpeakers + " people mainly in " + this.regionSpoken + "."); 
      System.out.println("The language spoken follows the order:" + this.wordOrder); 
    }

  public static void main(String[] args) {
    SinoTibetan mandarin = new SinoTibetan("Mandarin Chinese", 1100000);
    mandarin.getInfo(); 
    SinoTibetan burmese = new SinoTibetan("Burmese", 43000000); 
    burmese.getInfo();  
  }
  }
  
  

That’s a whole other issue. Is there a base class you’re overriding getInfo() from? I think otherwise it will throw an error.

Documentation: https://docs.oracle.com/javase/8/docs/api/java/lang/Override.html

Article of interest (I think this is most relevant to your project and will give you a better idea of how to structure it):
https://www.tutorialspoint.com/importance-of-override-annotation-in-java


By the examples you give, I think getInfo() would not need the @Override in the base Language class, but it would need it in its child classes Mayan and SinoTibetan when they define getInfo().

1 Like

My program is working now. I think OverRide is only for child classes on the same page