Define a method
public void greet() {
System.out.println(“Hello, World!”);
}
Create a class
Public Class NameOfClass {
}
Create a main method
public class MyClass {
public static void main(String[] args) {
// Code inside the main method
}
}
Create an object
MyClass myObject = new MyClass();
instate a variabe
x=5;
Create a Java class named MyClass that prints out “The value of x is” concatenated with the value of a variable.
public class MyClass {
int x; // instance variable
public static void main(String[] args) {
// Creating an object of the MyClass class
MyClass myObject = new MyClass();
// Accessing instance variable and setting its value
myObject.x = 10;
// Accessing instance variable and printing its value
System.out.println("The value of x is: " + myObject.x);
} }