Buscar

Can we have two methods in a class with the same name? We can define two methods in a class with the same name but with different number/type of p...

Can we have two methods in a class with the same name?

We can define two methods in a class with the same name but with different number/type of parameters.
Which method is to get invoked will depend upon the parameters passed.
a) Only afirmation 1 is correct.
b) Only afirmation 2 is correct.
c) Afirmations 1 and 2 are correct.
d) None of the afirmations are correct.

Essa pergunta também está no material:

23 pág.

Linguagem de Programação Java Universidade PaulistaUniversidade Paulista

💡 1 Resposta

User badge image

Ed Verified user icon

Sim, é possível ter dois métodos em uma classe com o mesmo nome, desde que eles tenham um número ou tipo de parâmetros diferentes. O método que será invocado dependerá dos parâmetros passados. Portanto, a afirmativa 1 está correta. A afirmativa 2 também está correta, pois é possível definir métodos com o mesmo nome, mas com diferentes parâmetros. Portanto, a resposta correta é a alternativa c) Afirmativas 1 e 2 estão corretas.

0
Dislike0

✏️ Responder

SetasNegritoItálicoSublinhadoTachadoCitaçãoCódigoLista numeradaLista com marcadoresSubscritoSobrescritoDiminuir recuoAumentar recuoCor da fonteCor de fundoAlinhamentoLimparInserir linkImagemFórmula

Para escrever sua resposta aqui, entre ou crie uma conta

User badge image

Outros materiais