Question: Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify
Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. You can give it a default value of 19090.
class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void setid(int newid) { id = newid; } public void setname(String newname) { name = newname; } public String toString() { String result = Integer.toString(id)+" "+name; return result; } } class TestStudent1 { public static void main(String args[]) {Student s0=new Student(); System.out.println(s0); Student s1=new Student(); s1.setid(312); s1.setname("Patrick"); System.out.println("ID is " + s1.getid()); System.out.println("The student name is " + s1.getname()); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
