I am learning the use of set
, get
, methods, classes, etc. I have the following code, very simple, but it gives me an error when executing. They are two classes, clase1
and clase2
.
The codes are:
clase1
package paquete1;
import java.util.*;
public class clase1 {
private int edad;
clase1 obj1 = new clase1();
public void setEdad(int edad) {
this.edad = edad;
}
public int getEdad(){
return edad;
}
}
clase2
:
package paquete1;
public class clase2 {
public static void main (String[]args) {
clase1 obj2 = new clase1();
obj2.setEdad(10);
System.out.println("La edad es: "+obj2.getEdad());
}
}
When executing instead of telling me that the age is 10, it gives me the following error: