class Hello { public static void main(String[] args) { System.out.println("Helloworld"); } } } // extra bracket.
In this case, the error can be corrected simply by removing the additional bracket.
class Hello { public static void main(String[] args) { System.out.println("Helloworld"); } }
Case 2: Function outside the class
class Hello { public static void main(String args[]) { System.out.println("HI"); } } public static void func() { System.out.println("Hello"); }
In the previous example, we got an error because the method func() is outside the Hello class. You can delete it by moving the closing brace "}" to the end of the file. In other words, move the func() method to Hello.
class Hello { public static void main(String args[]) { System.out.println("HI"); } public static void func() { System.out.println("Hello"); } }
Case 3: Forgot to declare class at all
package A; class A { void fun1() { System.out.println("Hello"); } } package B; //getting class interface or enum expected public class B { public static void main(String[] args) { System.out.println("HI"); } }
package A; class A { void fun1() { System.out.println("Hello"); } } public class B { public static void main(String[] args) { System.out.println("HI"); } }
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.