Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why is compilation bringing out errors

–1 vote
asked Apr 16, 2021 by BAGUMA JOSEPH (110 points)
public class MyClass {
    public static void main(String args[]) {
      int x=10;
      int y=11;
      int z=x+y;

      System.out.println("Sum of x+y = " + z);
    }
}

1 Answer

+1 vote
answered Apr 19, 2021 by Peter Minarik (86,640 points)
First of all this is a Java code. Have you set the language to Java?

Second, in Java, every class has to go to its own file with the same name as the class itself. The default file you get is Main.java so your class must be called Main (not MyClass).

If you want to write your own class (MyClass) you have to create a new file (with the same name) and put the code there and call it from your Main.java file.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...