import java.lang.String; public class ListNode1<Customer> { private Customer cus
ID: 3543455 • Letter: I
Question
import java.lang.String;
public class ListNode1<Customer> {
private Customer customer;
private Customer hairType;
private Customer arrivalTime;
private Customer leaveTime;
private ListNode1<Customer> next;
public ListNode1 (Customer customer, Customer hairType, Customer arrivalTime, Customer leaveTime) {
this.customer = customer;
this.hairType = hairType;
this.arrivalTime = arrivalTime;
this.leaveTime = leaveTime;
next = null;
}
public ListNode1 (Customer customer, Customer hairType, Customer arrivalTime, Customer leaveTime, ListNode1<Customer> next){
this.customer = customer;
this.hairType = hairType;
this.arrivalTime = arrivalTime;
this.leaveTime = leaveTime;
this.next = next;
}
public Customer getCustomer(){
return customer;}
public void setCustomer(Customer customer){
this.customer = customer;}
public Customer getHairtype(){
return hairType;}
public void setHairtype(){
this.hairType = hairType;}
public Customer getArrivalTime(){
return arrivalTime;}
public ListNode1<Customer> getNext(){
return next;}
public void setNext (ListNode1<Customer> next) {
this.next = next;
}
public static void main(String[] args) {
ListNode1<Customer> node1 = new ListNode1<Customer>("John", "long hair", "17:45");
ListNode1<Customer> node2 = new ListNode1<Customer>("Matt"," curly hair", "17:50");
ListNode1<Customer> node3 = new ListNode1<Customer>("Joel", "buzz cut", "18:00");
ListNode1<Customer> node4 = new ListNode1<Customer>("Alan","military cut", "18:10");
node1.setNext(node2);
node2.setNext(node3);
node3.setNext(node4);
}
}
Can someone help me remove these errors:
after the public static void I have this error showing "non-static type variable Customer cannot be referenced from a static context" for each node. How do I fix this part and have the nodes print out after running?
Explanation / Answer
All the members fields of interface are by default public, static, final
Since inner interface is static by default, you can't refer Customer from static fields & methods
Because Customer is actually associated with instance of class, if it were associated with static field or method which is associated with class then it wouldn't make any sense
Consider this example here...
import java.lang.String;
public class ListNode1<Customer> {
private Customer customer;
private Customer hairType;
private Customer arrivalTime;
private Customer leaveTime;
private ListNode2<Customer> extends ListNode1<Customer> next;
publicListNode2<Customer> extends ListNode1<Customer> (Customer customer, Customer hairType, Customer arrivalTime, Customer leaveTime) {
this.customer = customer;
this.hairType = hairType;
this.arrivalTime = arrivalTime;
this.leaveTime = leaveTime;
next = null;
}
public ListNode2<Customer> extends ListNode1<Customer> (Customer customer, Customer hairType, Customer arrivalTime, Customer leaveTime, ListNode2<Customer> next){
this.customer = customer;
this.hairType = hairType;
this.arrivalTime = arrivalTime;
this.leaveTime = leaveTime;
this.next = next;
}
public Customer getCustomer(){
return customer;}
public void setCustomer(Customer customer){
this.customer = customer;}
public Customer getHairtype(){
return hairType;}
public void setHairtype(){
this.hairType = hairType;}
public Customer getArrivalTime(){
return arrivalTime;}
public ListNode2<Customer> extends ListNode1<Customer> getNext(){
return next;}
public void setNext (ListNode1<Customer> next) {
this.next = next;
}
public static void main(String[] args) {
ListNode2<Customer> node1 = new ListNode2<Customer>("John", "long hair", "17:45");
ListNode2<Customer> node2 = new ListNode2<Customer>("Matt"," curly hair", "17:50");
ListNode2<Customer> node3 = new ListNode2<Customer>("Joel", "buzz cut", "18:00");
ListNode2<Customer> node4 = new ListNode2<Customer>("Alan","military cut", "18:10");
node1.setNext(node2);
node2.setNext(node3);
node3.setNext(node4);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.