Error with fix in abstract class (Client is abstract; can not be instantiated)

0

I have an abstract class called Client with two subclasses. In the main file (called TestClient) I need to make an array but when I try to start it it gives me the message "Client is abstract; can not be instantiated".

    // Arreglo de clientes
        Cliente[] arreglo = new Cliente[10];
// Inicializa cada elemento del arreglo de clientes con un objeto de la clase Cliente
        int j = 1;
        for (int i = 0; i < 10; i++) {
            arreglo[i] = new Cliente("Cliente" + (i + 1),i);
        }

Mark me that error on the line:

  

array [i] = new Client ("Client" + (i + 1), i);

Will anyone know how to tell me why?

    
asked by Betsadi 24.10.2017 в 11:39
source

1 answer

1

If you have declared Client as an abstract class, it can not be instantiated, as the error indicates.

If you know something about abstract classes (which I hope you do because you are using it), you will know that in them you can not, for example, implement abstract methods, if you can implement methods but not abstract.

To work with an abstract class, what you have to do is create another class that inherits from it, where you will overwrite the methods declared as abstract in the Client class (if you have abstract methods in Client, if not).

Once you create a class that inherits from Client, you can work with that class: create objects, use their methods ...

Look at this document where it explains well what abstract classes are and how to use them. link

    
answered by 24.10.2017 в 12:29