Pular para o conteúdo

A Palavra-chave this

Introduzido
Material de apoio Assistir aula
English

A parameter can hide the field it should update

  • An object has name "Ada". setName(String name) runs name = name; with the argument "Bo".
  • Both unqualified names refer to the parameter, so the object still has "Ada". this.name = name assigns the parameter value to the field instead.
A parameter can hide the field it should update: in setName(String name), name = name assigns the parameter to itself, so the object keeps "Ada"; this.name = name assigns the parameter value "Bo" to the field

Material de apoio

Entrar ou criar conta

IGCSE, A-Level & AP