0

Please help me ( what is the Error here )

Import java.lang.override; Public static void main(String[] args) { GreetingMessage gm = new GreetingMessage(){ @override Public void greet(String name) { System.out.println(“Hello “ + name); } }; gm.greet(“Theo”); }

27th Oct 2020, 6:26 PM
AmgKhvbbi Schweppes
AmgKhvbbi Schweppes - avatar
2 Réponses
+ 4
There are several errors here, so, I'll post some working code for you to look at and a link on inline/anonymous classes for you to review. Also, note that an override isn't needed in this case, and you don't need to import override as it is implicitly already imported in all java programs. public interface GreetingMessage { public void greet(String name); } public class Program { public static void main(String[] args) { GreetingMessage gm = new GreetingMessage(){ public void greet(String name) { System.out.println("Hello " + name); } }; gm.greet("Theo"); } } https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html
27th Oct 2020, 7:14 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
thanks bro
27th Oct 2020, 10:38 PM
AmgKhvbbi Schweppes
AmgKhvbbi Schweppes - avatar