am writing a program on linked list in Java but am confused on why the right values are not been added. I want to add the student name and StudentNo together as they for one student. Below is the code.
package linked;
public class PlsWork {
private String name;
private int studentNo;
public PlsWork(String name, int studentNo){
this.name=name;
this.studentNo=studentNo;
}
public String getname(){
return name;
}
public int getstudentNo(){
return studentNo;
}
}
package linked;
import java.util.LinkedList;
public class Linked {
public static void main(String[] args) {
LinkedList myLinkedList = new LinkedList();
myLinkedList.addFirst("A");
System.out.println(myLinkedList);
PlsWork ok = new PlsWork("obinna",3);
myLinkedList.add(ok);
System.out.println(myLinkedList);
}
}
when i run the code i get the answer below [A, linked.PlsWork@6d06d69c]
Instead of [A,obinna 3]