Answering your question what are the methods that can be used in a java class? and how it is structured.
In java the basic structure of a class usually follows the following scheme:
- attributes
- Builders
- Getters (accessors).
- Setters (mutators).
- class methods.
With regard to your question what are the methods that can be used in a java class?
The essential methods when implementing your Java class and that are essential but not mandatory are:
- Builders
- Getters (accessors).
- Setters (mutators).
In code the basic structure would be as follows:
public class Persona(){
//Atributos de la clase
private String nombre;
private int edad;
//Constructores
//Constructor Vacio
public Persona(){
}
//Constructor con Parametros
public Persona(String nombre,int edad){
this.nombre = nombre;
this.edad = edad;
}
//Metodos accesadores y mutadores
public string getNombre(){
return nombre;
}
public void setNombre(String nombre){
this.nombre=nombre;
}
public string getEdad(){
return edad;
}
public void setEdad(int edad){
this.edad=edad;
}
}
To make it clearer we will analyze the code:
The first thing we do is declare the attributes of the class, it is recommended
declare the attributes at the beginning of the class.
After we implement the constructors, you can implement as many builders as you need, this is called overload. , and you will ask what the builders will do for us? will serve to instantiate our classes or our objects.
Finally we have the accessor and mutator methods ( getters and setters ) that are the encapsulation of the declared attributes.
Then the getters or get, will allow us to obtain and show what our declared variable has and the setter or set will allow us to modify the value that our variable has.
The class methods you can implement are the ones you need. there is no maximum or limit of methods.
I would recommend studying a bit what is encapsulation, polymorphism, object-oriented programming, interfaces, inheritance is the most basic thing you will use when you work in java.