Java - Interface

Asked

Viewed 16 times

0

I was studying interface and I came up with a question in the code below:

public class TesteGerente {

 public static void main(String[] args) {

            Autenticavel referencia = new Cliente();

            Gerente g1 = new Gerente();
            g1.setNome("Marco");
            g1.setCpf("235568413");
            g1.setSalario(5000.0);

            System.out.println(g1.getNome());
            System.out.println(g1.getCpf());
            System.out.println(g1.getSalario());
            System.out.println(g1.getBonificacao());
   }
}

The part of new Cliente using as reference the interface he signs (Autenticavel referencia = new Cliente()) , what would be the real advantage of creating the object using this type of reference, and if something changes in code development ?

  • In addition to the duplicate suggested above, these may also help: https://answall.com/q/86484/112052 | https://answall.com/q/107524/112052

  • In this case, artificial examples of use do not demonstrate advantages of use.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.