in java Write a Generic class named Node. The class should hold a field named va
ID: 3575266 • Letter: I
Question
in java Write a Generic class named Node. The class should hold a field named value which will eventually hold a value of some instantiated type. A second field named next will hold a reference to the Node class itself. This class represents nodes that could be used in a singly-linked list. Make sure the class has the following methods :
A constructor that takes two arguments and assigns them into the attributes value and next.
Setters and getters for the two attributes – setNext( ), getNext( ), setValue( ) getValue( ).
Explanation / Answer
public class Node<T>{
T value;
Node<T> next;
private Node(T value, Node<T> next){
setValue(value);
setNext(next);
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
public Node<T> getNext() {
return next;
}
public void setNext(Node<T> next) {
this.next = next;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.