I'm getting into some territory I have never treaded before....

What I have is an Abstract class "Person" with an abstract class "Employee" that extends "Person" and then three concrete classes within "Employee" named: Agent, Accountant, and WebDesigner.

sudo:

abstract class Person{
    abstract class Employee extends Person implements myInterface{
        class Agent{}
        
        class Accountant{}

        class WebDesigner{}
    }

    class Client{}
}

What I am trying to do is in my driver class is to create an arraylist of abstract type Employee. something like this:

ArrayList<Person.Employee> employeeList = new ArrayList<Person.Employee>();

employeeList.add(new Person.Employee.agent(myStringArray));

But I get the error "an enclosing instance that contains <my reference> is required"

The abstract class within the abstract class is really throwing me off... is there
A) a better way to do this? or,
B) a fairly easy way to fix this error and add a new object to my arraylist?

You're getting into a tangle with inner classes and whether they are static or not. Rather than get into all that obscure theory, I would not make them inner classes at all. You can keep them all in the same package if you need to group them together for access control or whatever.

abstract class Person{}
abstract class Employee extends Person implements myInterface{}
class Agent extends Employee { ... }

ArrayList<Employee> employeeList = new ArrayList<Employee>();
employeeList.add(new Agent(myStringArray));

That worked great! I don't know why our professor was doing it in such a confusing way if that works exactly as intended....

But thanks for the advice!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.