What can a class have in Java?

A class describes the data and the methods of its objects . Every object belongs to some class. An object contains data (instance variables) representing its state, and instance methods, which are the things it can do. A class may also contain its own data (class variables) and class methods.

Read more

When should I define a class?

As a rule of thumb, when you have a set of data with a specific structure and you want to perform specific methods on it , use a class. That is only valid, however, if you use multiple data structures in your code. If your whole code won’t ever deal with more than one structure.

Read more