~/ 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/8fa37489-d406-4464-b339-c068afe9014a/flashcard utf-8 LF