Answer to Question #347808 in Java | JSP | JSF for stephanie

Question #347808

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




1
Expert's answer
2022-06-06T08:58:11-0400
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;
    }


    

}



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS