To create a class, use the keyword class
:
Main.java
Create a class named "Main
" with a variable x:
public class Main {
int x = 5;
}
Remember from the Java Syntax chapter that a class should always start with an uppercase first letter, and that the name of the java file should match the class name.
Practice Excercise Practice now