DEV Community

nipun sanjula samarakoon
nipun sanjula samarakoon

Posted on

Create an Object in java

In Java, an object is created from a class.
To create an object of Main, specify the class name, followed by the object name, and use the keyword new:

public class Main {
int x = 5;

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

Top comments (0)