-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClase Java 6.java
More file actions
61 lines (27 loc) · 1.26 KB
/
Clase Java 6.java
File metadata and controls
61 lines (27 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package clase.java.pkg6;
public class ClaseJava6 {
int numero;
int n = 10;
int y;
String nombre;
String nombre_gato;
public ClaseJava6(String w, String p, String g){ //Esto es un Constructor.
numero = 23;
y = n;
nombre = w;
String nombre_perro = p; //Lo que se declare dentro, solo se puede utilizar en el constructor.
nombre_gato = g;
System.out.println("Su perro se llamaba: " + nombre_perro);
/*
Constructor: No tiene un tipo de retorno (int, String, void, etc), ni siquiera void.
Esto lo diferencia de los métodos. No puede devolver valores.
*/
}
public static void main(String[] args) {
ClaseJava6 miObjeto = new ClaseJava6("Marta","Canela","Polimedia");
System.out.println(miObjeto.numero);
System.out.println(miObjeto.y);
System.out.println("Su nombre era: " + miObjeto.nombre);
System.out.println("El nombre de su gato era: " + miObjeto.nombre_gato);
}
}