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.");
}
}
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)