JAVA BASIC POO
Links
//JAVA <
public class Basic_poo {
private String nombre;
private int edad;
//1-OBJETOS
//un objeto es una instancia de una clase
//2-CONSTRUCTORES: sirven para crear objetos
//A constructor in Java is a special method that is used to initialize objects.
//The constructor is called when an object of a class is created. It can be used to set initial values for object attributes:
//Note that the constructor name must match the class name,and it cannot have a return type (like void).
//Also note that the constructor is called when the object is created.
//All classes have constructors by default: if you do not create a class constructor yourself,
//Java creates one for you. However, then you are not able to set initial values for object attributes.
//basico
public Basic_poo() {
}
//con parĂ¡ametros
public Basic_poo(String nombre, int edad) {
this.nombre = nombre;
this.edad = edad;
}
//3-GETTER : Deben tener un RETURN
public String getNombre() {
return nombre;
}
public int getEdad() {
return edad;
}
//3-SETTER: son void, no devuelven nada. Establecen el valor
public void setNombre(String nombre) {
this.nombre = nombre;
}
public void setEdad(int edad) {
this.edad = edad;
}
//4-METHODS
static void myMethod(String fname) {
System.out.println(fname + " Refsnes");
}
// public String Devuelve2Valores(){
// return (nombre, edad);
// }
//MULTIPLE PARAMETERS
static void myMethod(String fname, int age) {
System.out.println(fname + " is " + age);
}
//DEVOLVIENDO RETURN VARIABLES
public int DevuelveInt() {
return 1;
}
//5-Listados
}