Main не является абстрактным и не переопределяет абстрактный метод get () в Shape. Publi c класс Main extends Shape? - PullRequest
0 голосов
/ 27 апреля 2020

Main не является абстрактным и не переопределяет абстрактный метод get () в Shape publi c класс Main extends Shape ????

Я не могу переопределить абстрактный метод в основном классе. Как это сделать? Я создал абстрактный класс и добавил к нему методы, и если я сделаю основной класс абстрактным, он запросит один метод publi c. Абстрактным методом является Shape, который переопределяет методы add, get, size, clear. Также у меня мало проблем с Get Method .??

import java.io.*;
import java.util.*;


interface List{
void add();  
int get();
int size();
void clear();
}

abstract class Shape implements List{  
 private E head;
    private int size=0;
   static class E { 

        int data; 
        E next; 

        E(int d) 
        { 
            data = d; 
            next = null; 
        } 
    }

public void add(E e)
  {
      if(this.head==null)
      {
          this.head=e;
          this.size+=1;
      }
      else
      {
          E current = this.head;
          while(current.next!=null)
          {
              current=current.next;
          }
          this.size+=1;
          current.next=e;
      }
  }
public int get(int index)
  {
    //   E current = this.head;
    //   while((index) && (current!=null))
    //   {
    //       current=current.next;
    //       index-=1;
    //   }
    //   return current.data;
    return 0;
  }

  public int size()
  {
    return this.size;
  }

  public void clear()
  {
   this.head=null;
   this.size=0;
  }  
int get();
 int size();
 void clear();

}  



 public class Main extends Shape
{
   private E head;
   private int size=0;
   static class E { 

        int data; 
        E next; 

        E(int d) 
        { 
            data = d; 
            next = null; 
        } 
    }



  public int get(int index)
  {
    //   E current = this.head;
    //   while((index) && (current!=null))
    //   {
    //       current=current.next;
    //       index-=1;
    //   }
    //   return current.data;
    return 0;
  }

  public int size()
  {
    return this.size;
  }

  public void clear()
  {
   this.head=null;
   this.size=0;
  }

   public static void main(String[] args) 
   {
       // adding values to linkedlist here
     Main linkedlist = new Main();

     E e = new E(1);
     linkedlist.add(e);
     E e2 = new E(2);
     linkedlist.add(e2);
      E e3 = new E(3);
     linkedlist.add(e3);
     E e4 = new E(4);
     linkedlist.add(e4);

     E root = linkedlist.head;
     // traversing the linkedlist
     while(root!=null)
     {
         System.out.println(root.data);
         root=root.next;
     }
     // checking the size of linkedlist
     System.out.println(linkedlist.size());

     //get 
     // System.out.println(linkedlist.get(2));

     // clearing the linkedlist
     linkedlist.clear();
     //again checking the size after clear
     System.out.println(linkedlist.size());





   }
}
...