I would like to create one class and then another class inside. This class will be directly connected with superior class. It should look like following (not code, just schema):
class company
string name
class employee
string firstName, lastName;
int age
Of course, I have constructors etc. Now I want to create company 'g' and employee f m of age 2 inside of that company. Maybe it is not justified to make class inside another class and I should just create class employee with field company?
Code below does not work, compiler says: an enclosing instance that contains company.employee is required
nowa=new company('g',2);
nowa.prac=new company.employee('f','m',2);
Full code below:
public class program
{
public static class company
{
char name;
int duration;
public class employee
{
public char imie,nazwisko;
public int wiek;
public employee(char a,char b,int w)
{
imie=a;
nazwisko=b;
wiek=w;
}
}
public company(char n,int c)
{
name=n;
duration=c;
}
}
public static void main(String []args)
{
company nowa=new company('g',2);
nowa.empl=new employee('f','m',2);
}
}