java class

Java
public class Lightsaber {
  // properties
  private boolean isOn;
  private Color color;
  
  // constructor
  public Lightsaber(Color color) {
    this.isOn = false;
    this.color = color;
  }
  
  // getters
  public Color getColor() {
    return color;
  }
  public boolean getOnStatus() {
    return isOn;
  }
  
  // setters
  public void turnOn() {
    isOn = true;
  }
  public void turnOff() {
    isOn = false;
  }
}



// Implementation in main method:
public class test {
  public static void main(String[] args) {
    Lightsaber yoda = new Lightsaber(green);
    yoda.turnOn();
  }
}
    //	Example : TestClass (Can be predefined or user-defined)
public class TestClass {
  // properties
  private int id = 111;
  
  // constructor
  public TestClass(){
    super();
  }
  
  // method
  public void test(){
    // some code here
  }
}// this might help you understand how classes work
public class MathTest {

    public static void main(String[] args) {

        class MathAdd {

            int num1;
            int num2;

            public int addNumbers() {

                int addThemUp = num1 + num2;
                return addThemUp;
            }
        }

        MathAdd addition = new MathAdd(); // create a new instance of the class

        // you can access variables from the class 
        addition.num1 = 10; 
        addition.num2 = 20;

        // and use the method from the class to add them up
        System.out.println(addition.addNumbers());

    }
}public class MyClass {
  int x = 5;

  public static void main(String[] args) {
    MyClass myObj = new MyClass();
    System.out.println(myObj.x);
  }
}
 
add

Source

Also in Java: