The output of the above code will be:

Peter is 17 years old!

Explanation:

The code defines a class named "Person" with two instance variables: "name" and "age". It also has a constructor that takes two parameters: "name" and "age" and initializes the instance variables with the given values.

In the main method, an object of the Person class is created with the name "Peter" and age 17. The object's "name" and "age" instance variables are accessed using the dot operator and printed to the console using the "println" method.

Therefore, the output of the program is "Peter is 17 years old!"


原文地址: https://www.cveoy.top/t/topic/g0um 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录