Classes are the basic components in object-oriented programming, essentially a program created using a programming language that follows this paradigm it is composed of various classes, which could also be defined as its cells. A Class in reality it is not something 'concrete', but rather the concept of something that exists within the program, a sort of mold that is used to create an object that represents in concrete that Class. Only after the class has materialized (it has been instantiated) will it be possible to use its functionalities, therefore its methods and its variables (except for the methods and variables with the static modifier, which we will see subsequently).
Let's see a simple example of a Java class that contains the basic components:
public class SumClass {
// Instance variables
private int a;
private int b;
// Constructor method without parameters
public SumClass() {
}
// Constructor method with parameters
public SumClass(int a, int b) {
this.a = a;
this.b = b;
}
// Setter and Getter Methods of a
public void setA(int a) {
this.a = a
}
public int getA() {
return a;
}
// Sum Method
public int sumNumbers() {
return a + b;
}
}Each element defined within the class has a specific purpose, which we will examine gradually.
