-
Notifications
You must be signed in to change notification settings - Fork 0
/
mensch.java
90 lines (66 loc) · 1.34 KB
/
mensch.java
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
public class Main
{
public static void main(String args[])
{
Mensch helmut = new Mensch("Helmut",35, 0);
System.out.println("Anzahl Menschen = " + Mensch.getAnzahlMenschen());
Mensch uwe = new Mensch("uwe",35, 0);
helmut.setAlter(5);
System.out.println("helmut iq = " + helmut.iq);
helmut.bildung();
System.out.println("helmut iq = " + helmut.iq);
helmut.bildung(20);
System.out.println("helmut iq = " + helmut.iq);
Hund otto = new Hund();
otto.setAlter(20);
System.out.println(helmut.getAlter());
System.out.println("Anzahl Menschen = " + Mensch.getAnzahlMenschen());
System.out.println(helmut.toString());
}
}
public abstract class Lebewesen
{
String name;
int alter;
void setAlter(int alter)
{
this.alter = alter;
}
public int getAlter()
{
return alter;
}
}
public final class Mensch extends Lebewesen
{
int iq = 0;
private static int anzahlMenschen = 0;
public static int getAnzahlMenschen()
{
return anzahlMenschen;
}
void bildung()
{
iq += 5;
}
void bildung(int wieviel)
{
iq += wieviel;
}
Mensch(String name, int alter, int iq)
{
this.name = name;
this.alter = alter;
this.iq = iq;
anzahlMenschen++;
}
Mensch () {}
@Override
public String toString()
{
return String.format("Name: %s, Alter: %s, IQ: %s", name, alter, iq);
}
}
public class Hund extends Lebewesen
{
}