Code Lab

Mode entretien. Minuteur de 4 min, sans indices ni autocomplétion

Static method

FacileClasses4 min

Write a class Person. The constructor takes a first name and a last name. If they are not given, use 'John' and 'Doe'. The method sayFullName() returns the first and last name with a space between them.

Also add a static method greetExtraTerrestrials(raceName). It returns the string 'Welcome to Planet Earth ' with the race name at the end.

Exemples

new Person().sayFullName()

Renvoie 'John Doe'

new Person('Jane', 'Smith').sayFullName()

Renvoie 'Jane Smith'

Person.greetExtraTerrestrials('Martians')

Renvoie 'Welcome to Planet Earth Martians'

The method is called on the class itself.

Source

Chargement de l'éditeur...
  1. Default name
  2. Name from the arguments
  3. The greeting is called on the class

Les tests cachés se lancent à la soumission