l1) in java Write a Generic class named Node. The class should hold a field name
ID: 3578794 • Letter: L
Question
l1)
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
Hope this is clear and requires no explanation
public class Node<E> {
private E value;
private Node<E> next;
public Node(E value, Node<E> next) {
this.value = value;
this.next = next;
}
public E getValue() {
return value;
}
public void setValue(E value) {
this.value = value;
}
public Node<E> getNext() {
return next;
}
public void setNext(Node<E> next) {
this.next = next;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.