~/ learn/ java-from-zero/ cards/ Classes, objects, new & constructors
1 of 4

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/73c99b6d-7e11-4548-89f4-9996c1c2a0d1/flashcard utf-8 LF