Java Java Objects Meet Objects Final

Error in final java objects

I keep receiving this error when I have the same code in my example.java

Example.java:13: error: ';' expected
dispenser.getCharacterName());

This is the code: public class Example {

public static void main(String[] args) { // Your amazing code goes here... System.out.println("We are making a new PEZ Dispenser"); PezDispenser dispenser = new PezDispenser("Yoda"); System.out.printf("The dispenser is %s %n", dispenser.getCharacterName() ); String before = dispenser.swapHead("Darth Vader"); System.out.printf("It was %s but Chris switched it to %s %n" before, dispenser.getCharacterName()); }

}

2 Answers

Mihai Craciun
Mihai Craciun
13,518 Points
This is the code: public class Example {

public static void main(String[] args) { 
// Your amazing code goes here... 
System.out.println("We are making a new PEZ Dispenser");
 PezDispenser dispenser = new PezDispenser("Yoda"); 
System.out.printf("The dispenser is %s %n", dispenser.getCharacterName() ); 
String before = dispenser.swapHead("Darth Vader"); 
System.out.printf("It was %s but Chris switched it to %s %n" before, dispenser.getCharacterName()); 
  }
//^ this " } " is extra
}
Daniel Mallett
Daniel Mallett
14,582 Points

It looks like you have 1 too many closing braces at the end of your program. Or you just need to move the closing brace down one . Which means it is not picking up the semi-colon.