DEV Community

nipun sanjula samarakoon
nipun sanjula samarakoon

Posted on

Java Class Attributes

Create a class called "Main" with two attributes: x and y:

public class Main {
int x = 5;
int y = 3;
}

Accessing Attributes

You can access attributes by creating an object of the class, and by using the dot syntax (.):

**public class Main {
int x = 5;

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

Top comments (0)