Hallo liebes Forum,
ich habe hier ein für mich nicht definierbares Problem.
Hier der Code:
Superclass
Subclass1
Subclass2
ich habe hier ein für mich nicht definierbares Problem.
Hier der Code:
Superclass
Java:
package Prasenzubung_Ubung06_Aufgabe02;
public class Aufgabe02_Mitarbeiter {
protected String name, rvs;
public void MitarbeiterInfo() {
// Java does not have any concept of global variables.
// There is either an instance variable or a class variable.
// A class variable is also known as static field/variable ,
// and is shared by all the objects/instances of the class
// ( hence the name "class variable").
System.out.println("Name: "+name);
System.out.println("RVS Nr.: "+rvs);
}
}
}
Subclass1
Java:
package Prasenzubung_Ubung06_Aufgabe02;
public class Aufgabe02_Angestellter extends Aufgabe02_Mitarbeiter {
protected String sts = "Angestellter";
protected double gehalt;
public void MitarbeiterInfo() {
//Create object and refer from object to the other ClassMethod
Aufgabe02_Mitarbeiter ref = new Aufgabe02_Mitarbeiter(); //
ref.MitarbeiterInfo(); //non-static reference
// Aufgabe02_Mitarbeiter.MitarbeiterInfo();//static reference -> non-static method
// sysout("...")
sts = "Angestellter";
System.out.println("Status: "+sts);
System.out.println("Gehalt: "+gehalt);
}
//Konstruktor
protected Aufgabe02_Angestellter(String _name, String _rvs, int _gehalt)
{
Aufgabe02_Mitarbeiter ref = new Aufgabe02_Mitarbeiter(); //
// Aufgabe02_Angestellter thisref = new Aufgabe02_Angestellter();
_name = ref.name;
//_name = super.name;
_rvs = ref.rvs;
//_rvs = super.rvs;
_gehalt = (int) gehalt;
gehalt = (double) gehalt;
}
protected void SetGehalt(double a) {
gehalt = a;
}
}
Subclass2
Java:
package Prasenzubung_Ubung06_Aufgabe02;
public class Aufgabe02_Arbeiter extends Aufgabe02_Mitarbeiter {
// The static keyword in Java means that the variable or function is shared
// between all instances of that class as it belongs to the type, not the
// actual objects themselves. So if you have a variable:
// private static int i = 0; and you increment it ( i++ ) in one instance,
// the change will be reflected in all instances
protected String sts = "Arbeiter";
protected double stdl, stdg, lohn;
public void MitarbeiterInfo() {
// Create object and refer from object to the other ClassMethod
Aufgabe02_Mitarbeiter ref = new Aufgabe02_Mitarbeiter();
ref.MitarbeiterInfo();
//sysout("...")
System.out.println("Status: "+sts);
System.out.println("Stundenlohn: "+stdl);
System.out.println("Anzahl Stunden: "+stdg);
System.out.println("Arbeitslohn: "+lohn);
}
//Konstruktor
protected Aufgabe02_Arbeiter(String _name, String _rvs, double _stdg, int _lohn)
{
Aufgabe02_Mitarbeiter ref1 = new Aufgabe02_Mitarbeiter();
_name = ref1.name;
_rvs = ref1.rvs;
_stdg = stdg;
//_lohn = thisref.lohn;
_lohn = (int) GetLohn(); // cast to continue
}
public double GetLohn() {
lohn = (double) stdl*stdg; // Cast for correct data type.
return lohn;
}
public double SetLohn(double a) {
stdl = a;
return stdl;
}
}