Override toString() in the Student and Employee classes. For example, if a Student object is created like this:
Student student = new Student("Maria",18,"BSIT",1);
then the Student class’ toString() method will return this string:
Maria 18 BSIT 1
public class Student {
private String name;
private int age;
private String fac;
private int course;
private String strok = "";
public Student(String name, int age, String fac, int course) {
this.name = name;
this.age = age;
this.fac = fac;
this.course = course;
}
public String toString() {
strok = name + " " + age + " " + fac + " " + course;
return strok;
}
}
public class Student {
private String name;
private int age;
private String fac;
private int course;
private String strok = "";
public Student(String name, int age, String fac, int course) {
this.name = name;
this.age = age;
this.fac = fac;
this.course = course;
}
public String toString() {
strok = name + " " + age + " " + fac + " " + course;
return strok;
}
}
Comments
Leave a comment