Inside the Person class you just created, declare two instance variables: String name and int age. Case 1 John Doe is 30 years old.\n Jane Smith is 28 years old.\n Alice Brown is 25 years old.\n file name: Demo2.java public class Demo2 { public static void main(String[] args) { // Creating three instances and directly setting the variables Person person1 = new Person(); person1.name = "John Doe"; person1.age = 30; Person person2 = new Person(); person2.name = "Jane Smith"; person2.age = 28; Person person3 = new Person(); person3.name = "Alice Brown"; person3.age = 25; System.out.println(person1.name + " is " + person1.age + " years old."); System.out.println(person2.name + " is " + person2.age + " years old."); System.out.println(person3.name + " is " + person3.age + " years old."); } }
Alert dont submit
Inside the Person class you just created, declare two instance variables: String name and int age.
Case 1
John Doe is 30 years old.\n
Jane Smith is 28 years old.\n
Alice Brown is 25 years old.\n
file name: Demo2.java
public class Demo2 {
public static void main(String[] args) {
// Creating three instances and directly setting the variables
Person person1 = new Person();
person1.name = "John Doe";
person1.age = 30;
Person person2 = new Person();
person2.name = "Jane Smith";
person2.age = 28;
Person person3 = new Person();
person3.name = "Alice Brown";
person3.age = 25;
System.out.println(person1.name + " is " + person1.age + " years old.");
System.out.println(person2.name + " is " + person2.age + " years old.");
System.out.println(person3.name + " is " + person3.age + " years old.");
}
}

Step by step
Solved in 4 steps with 2 images









