Complete the code to declare an instance variable named age of type int.
public class Person { [1] age; }
static makes the variable shared by all objects, not an instance variable.void is only for methods, not variables.The keyword int declares the variable age as an integer instance variable.
Complete the code to assign the value 25 to the instance variable age inside the constructor.
public class Person { int age; public Person() { [1] = 25; } }
age() which looks like a method call.Person.age which is for static variables.Use this.age to refer to the instance variable age inside the constructor.
Fix the error in the code by completing the declaration of the instance variable name of type String.
public class Person { [1] name; }
static String makes it a class variable, not an instance variable.void String is invalid syntax.The correct way to declare an instance variable of type String is simply String name;.
Fill both blanks to complete the constructor that sets the instance variables name and age.
public class Person { String name; int age; public Person(String name, int age) { this.name = [1]; this.age = [2]; } }
"name" instead of the parameter name.0 instead of the parameter age.The constructor parameters name and age are assigned to the instance variables using this.name = name; and this.age = age;.
Fill all three blanks to complete the method that returns a description using instance variables name and age.
public class Person { String name; int age; public String getDescription() { return [1] + " is " + [2] + [3]; } }
name or age." years old".The method returns a string combining the instance variable name, the integer age, and the string literal " years old".