DEV Community

nipun sanjula samarakoon
nipun sanjula samarakoon

Posted on

1 1

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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay