public class Student练习35

2023-06-15  本文已影响0人  哈迪斯Java

public class Student {
String name;
int age;

public Student(String name, int age) {
    this.name = name;
    this.age = age;
}

public String toString() {
    return "我叫" + name + ",今年" + age + "岁。";
}

public static void main(String[] args) {
    Student s1 = new Student("张三", 16);
    System.out.println(s1);
    Student s2 = new Student("李四", 19);
    System.out.println(s2);
}

}

上一篇下一篇

猜你喜欢

热点阅读