Untitled
unknown
java
10 months ago
1.1 kB
9
Indexable
class People {
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "People{" +
"age=" + age +
'}';
}
}
class Student extends People {
private String name;
private int id;
public Student(String name, int id) {
this.name = name;
this.id = id;
}
public String getName() {
return name;
}
public int getId() {
return id;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", id=" + id +
'}';
}
}
public class Solution {
public static void main(String[] args) {
Student s1 = new Student("John", 123);
Student s2 = new Student("Jane", 124);
s1.setAge(45);
s2.setAge(35);
System.out.println(s1.getAge()); // 45
System.out.println(s2.getAge()); // 35
}
}
Editor is loading...
Leave a Comment