Beginning Java inheritance question involving a doubly linked list inheriting from a circularly linked list

I am trying exercises from a book on programming and am stuck trying to create a doubly linked list subclass that inherits from a circularly linked superclass. The subclass has a nested class for a list node that separately inherits from a list node in the superclass.

For example:

public Superclass {
   protected Node<E> {
      E element
      Node<E> next
      public Node(E e, Node<E> n) {
         element = e
         next = n
      }
      // access/update methods such as getElement, getNext, set Next ...
   }
   protected Node<E> tail
   protected int size
   // access methods including size(), isEmpty(), first(), last() ...
   // update methods including rotate(), addFirst(E e), addLast(E e), removeFirst() ...
   //    The code for removeFirst which is not overridden is:
   //         if list not empty:
   //         Node<E> head = tail.getNext()
   //         if (head == tail) {
   //            tail = null
   //         } else {
   //            tail.setNext(head.getNext())
   //         }
   //         size--
}

And:

public Subclass extends Superclass {
   protected InheritedNode<E> extends Superclass.Node {
      private InheritedNode prev
      public InheritedNode(E e, Node n, InheritedNode p) {
         super(e, n)
         prev = p
      }
      // access/update methods including getPrev() and setPrev(InheritedNode<E> p) { prev = p }
   }

   // Override Superclass method
   public void addFirst(E e) {
      Create a new InheritedNode if list is null and set prev and next to self
         Or
      addBetween(e, (InheritedNode<E>) tail, (InheritedNode<E>) tail.getNext())
   }

   // private update method
   private void addBetween(E e, InheritedNode<E> predecessor, InheritedNode<E> successor) {
      InheritedNode<E> newest = new InheritedNode<E>(e, predecessor, successor)
      predecessor.setNext(newest);
      successor.setNeext(newest);
      size++;
   }
}

The addFirst and addBetween methods in the subclass were copied directly from a previous exercise to create a circular doubly linked list that ran fine, and the code calling the subclass method was unchanged:

public static void main(String[] args) {
   Superclass Name = new Superclass();
   Name.addFirst("A");      // This method was overridden
   Name.addLast("B");      // This method was not overridden
   Name.addLast("C");
   // And code to print the list contents using the rotate() method
}

There is a problem as soon as the third node with “C” as the element is added that did not manifest in any previous exercise. The output reads as follows:
A
A B
B C B
If a fourth node is added using addLast(“D”), the output is:
C D C D
If the not-overridden removeFirst method from Superclass is called, the output is:
D D D

The list is losing all previous nodes besides the first two somewhere between the superclass and subclass, and I have been unable to determine why.

Using the debug feature of the IDE, I stopped execution in the Subclass addFirst method after the third node was added. The debug feature showed that only the immediate next and prev nodes had the correct elements. The sequence of nodes after the third node was C C B C B C B C … while the sequence of nodes before the third node was C B A C A C A …

New contributor

chalk_eaux_2911 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật