~/ learn/ java-from-zero/ cards/ Classes & Objects
1 of 20

Type a constructor that initialises two fields

Type a constructor that initialises two fields

Answer

Dog(String name, int age) { this.name = name; this.age = age; }

this.name distinguishes the field from the parameter. No return type — not even void. Constructor name must match the class name exactly.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/5cc8924c-e49e-4051-99c1-31813ac70fed/flashcard utf-8 LF