166k views
5 votes
Write java code to create a new class called "student". an object of the student class has attributes like student id, name and address. instantiate an object of this class, with these attributes. thereafter, display these attributes to a user.

User Juharr
by
7.0k points

1 Answer

3 votes
Here you go. I added a constructor and a toString overload to make the object creation and printing as easy as possible.

public class student {
private String _id;
private String _name;
private String _address;

public student(String id, String name, String address) {
_id = id;
_name = name;
_address = address;
}

public String toString() {
return "Id: " + _id + "\\Name: " + _name + "\\Address: "+ _address;
}

public static void main(String[] args) {
student s1 = new student("S12345", "John Doe", "Some street");
System.out.println(s1);
}
}

User DerKlops
by
7.0k points