java - the type must implement the inherited abstract method -


i working on program intermediate java , feel have logic right, error in class introduction:

the type questionset must implement inherited abstract method iquestionset.add(iquestion)

i have method have question object parameter instead of iquestion(the interface question)

questionset:

package com.jsoftware.test;  import java.io.serializable; import java.util.arraylist;  public class questionset implements serializable, iquestionset{      arraylist<question> test = new arraylist<question>();      public questionset emptytestset(){         questionset set = new questionset();         return set;     }     public questionset randomsample(int size){         questionset set = new questionset();         if(size>test.size()-1){             for(int =1; i<test.size(); i++){                 int num = (int)(math.random()*test.size());                 set.add(test.get(num));             }         }else{             for(int =1; i<size; i++){                 int num = (int)(math.random()*test.size());                 set.add(test.get(num));             }         }         return set;     }     public boolean add(question q){         try{             test.add(q);             return true;         }catch(exception e){             return false;         }     }     public boolean remove(int index){         try{             test.remove(index);             return true;         }catch(exception e){             return false;         }     }     public question getquestion(int index){         return test.get(index);     }     public int size(){         return test.size();     }   } 

iquestionset:

package com.jsoftware.test;  /**  * interface represents set of question.   *   * @author thaoc  */ public interface iquestionset {      /**      * create empty test set.      * @return  return instance of test set.      */     public iquestionset emptytestset();      /**      * return test set consisting of random questions.      * @param size number of random questions.      * @return test set instance containing random questions.      */     public iquestionset randomsample(int size);      /**      * add question test set.        * @param question question      * @return true if successful.      */     public boolean add(iquestion question);      /**      *       * @param index remove question using index      * @return  true if index valid      */     public boolean remove(int index);      /**      * retrieving question using index      * @param index      * @return question if index valid, null otherwise.      */     public iquestion getquestion(int index);      /**      * return number of questions in test set.      * @return number of questions.      */     public int size(); } 

first change list of questions use type iquestion:

arraylist<iquestion> test = new arraylist<iquestion>(); 

then change method declaration:

public boolean add(iquestion q){     try{         test.add(q);         return true;     }catch(exception e){         return false;     } } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -