Witam,
W ramach nauki java napotkałem problem, którego nie rozumiem.
Mam 2 klasy
plik 1
public class Employee {
private static int nextId =1;
private String name;
private double salary;
public int id;
public Employee (String n, double s)
{
name = n;
salary =s;
id =0;
}
public String getName()
{
return name;
}
public double getSalary()
{
return salary;
}
public int getId()
{
return Id;
}
public void setId()
{
Id = nextId;
nextId++;
}
public static int getNextId()
{
return nextId;
}
}
'''
Plik nr 2
'''
public class StaticTest
extends Employee{
public static void main(String[] args) {
// TODO Auto-generated method stub
Employee[] staff = new Employee [3];
staff[0] = new Employee("Tomasz", 40000);
staff[1] = new Employee("Patryk", 20000);
staff[2] = new Employee("Ania", 30000);
for (Employee e: staff)
{
e.setId();
System.out.println("name" + e.getName() +".id" +e.getId() +".salary= "+e.getSalary());
}
int n = Employee.getNextId(); //Wywołanie metody statycznej
System.out.println("Następny wolny identyfikator="+n);
{
Employee e = new Employee("Grzegorz", 50000);
System.out.println(e.getName()+" " +e.getSalary());
}
}
}