继承中的构造函数出错了

时间:2017-09-11 18:14:43

标签: java

我在构造函数上做错了什么。我无法理解。我知道你可能不理解代码因为是另一种语言。我做了一个抽象类Metafores和子类,Aerio,Meikto,Stereo。请检查我的代码我在构造函数上做错了但我不知道它是什么。它应该怎么样?

    package eksetash1;


    public class Aerio extends Metafores {
        private int SyskeuasiasAeriou;

         public Aerio(){

        }
        public Aerio(int SyskeuasiaAeriou,int gettyposProiontos,int gettyposMetaforas,int gettyposMetrisis,String getonomaProiontos,double gettimiMonadas){
            super(gettyposProiontos,gettyposMetaforas,gettyposMetrisis,getonomaProiontos,gettimiMonadas);
            this.SyskeuasiasAeriou=SyskeuasiasAeriou;
        }

        @Override
        int gettyposProiontos() {
            return 3;
        }
    @Override
        int gettyposMetaforas() {
            return 0;
        }
        @Override
       int gettyposMetrisis(){
           return 0;
       }


      @Override
       double gettimiMonadas(){
           return 0;
       }
       @Override
       String getonomaProiontos(){
           return  null;
       }
    } //end 

    package eksetash1;


    public class Eksetash1 {
     static int N; //apo to plhktrologio
     static String Typos;
        public static void main(String[] args) {

       Metafores[] pin = new Metafores[N];
        for (int i = 0; i < 10; i++) {
            pin[i] = new Stereo();
            pin[i+10] = new Ygro();
            pin[i+20] = new Aerio();
            pin[i+30]=new Meikto();
        }


        // exceptions
        System.out.println("An einai Ygro,aeria,meiktou barous tha exoume eksairesh-grapste analoga");
                  if ((Typos = UserInput.getString()).equalsIgnoreCase("Ygro"))  {
            throw new IllegalExceptionMetaforas("Ta ygra dn metaferontai me aeroplano ");

       }
    System.out.println("An einai aeria tha exoume eksairesh");
         if ((Typos = UserInput.getString()).equalsIgnoreCase("aeria"))  {
            throw new IllegalExceptionMetaforas("Ta aeria dn metaferontai me to aeroplano");

       }
         System.out.println("An einai meiktou barous");
         if ((Typos = UserInput.getString()).equalsIgnoreCase("meiktou barous"))  {
            throw new IllegalExceptionMetaforas("Meiktou barous dn metaferontai me to aeroplano");

       }
    }
        }//end main


    package eksetash1;

    //class exception
    public class IllegalExceptionMetaforas extends RuntimeException{
        public  IllegalExceptionMetaforas (String s){
                          super(s);
    }
    }//end exception illegal

    package eksetash1;

    //another class Meikto
    public class Meikto extends Metafores {

        private String perigrafhSyskeuasias;
         public Meikto(){

        }
//constructor 
        public Meikto(String perigrafhSyskeuasias,int gettyposProiontos,int gettyposMetaforas,int gettyposMetrisis,String getonomaProiontos,double gettimiMonadas){
            super(gettyposProiontos,gettyposMetaforas,gettyposMetrisis,getonomaProiontos,gettimiMonadas);
            this.perigrafhSyskeuasias=perigrafhSyskeuasias;
        }

        @Override
        int gettyposProiontos() {
            return 4;
        }
    @Override
        int gettyposMetaforas() {
            return 0;
        }
        @Override
       int gettyposMetrisis(){
           return 0;
       }


      @Override
       double gettimiMonadas(){
           return 0;
       }
       @Override
       String getonomaProiontos(){
           return perigrafhSyskeuasias ;
       }
    }
    //end
    package eksetash1;

    // class Stereo
    public class Stereo extends Metafores {
    private String perigrafhYlikou;

        public Stereo(){

        }
// consructor
        public Stereo(String perigrafhYlikou,int gettyposProiontos,int gettyposMetaforas,int gettyposMetrisis,String getonomaProiontos,double gettimiMonadas){
            super(gettyposProiontos,gettyposMetaforas,gettyposMetrisis,getonomaProiontos,gettimiMonadas);
            this.perigrafhYlikou=perigrafhYlikou;
        }
        public void settyposProiontos(String typos){
            typos=typos;
        }


        @Override
        int gettyposProiontos() {
            return 1;
        }

    @Override
        int gettyposMetaforas() {
            return 0;
        }
        @Override
       int gettyposMetrisis(){
           return 0;
       }


      @Override
       double gettimiMonadas(){
           return 0;
       }
       @Override
       String getonomaProiontos(){
           return perigrafhYlikou;
       }

    } //end stereo

    //abstract class Metafores
    package eksetash1;


    public abstract class Metafores {
       abstract int gettyposProiontos();
       abstract int gettyposMetaforas();
      abstract int gettyposMetrisis();
       abstract String getonomaProiontos();
      abstract double gettimiMonadas();
      static String Typos;
       public Metafores(){

       }

//constructor

       public Metafores(int gettyposProiontos,int gettyposMetaforas,int gettyposMetrisis,int getonomaProiontos,double gettimiMonadas){

       }

       public void getTyposProiontos(){
           System.out.println("Grapste Stereo");
            if ((Typos = UserInput.getString()).equalsIgnoreCase("Stereo")) {

                Stero.settyposProiontos(1);
               Stereo.gettyposProiontos(1);//stereo=1 
       }
             System.out.println("Grapste Ygro");
            if ((Typos = UserInput.getString()).equalsIgnoreCase("Ygro")) {
                Ygro.settyposProiontos(2);
                Ygro.gettyposProiontos(2);//ygro=2
       }
             System.out.println("Grapste Aerio");
            if ((Typos = UserInput.getString()).equalsIgnoreCase("Aerio")) {
                Aerio.settyposPriontos(3);
                Aerio.gettyposProiontos(3);//aerio=3 
       } System.out.println("Grapste Meikto");
            if ((Typos = UserInput.getString()).equalsIgnoreCase("Meikto")) {
                Meikto.settyposProiontos(4);
                Meikto.gettyposProiontos(4);//meikto=4 
       }

    }
       public void getTyposMetaforas(){
           System.out.println("Grapste Stereo");
            if ((Typos = UserInput.getString()).equalsIgnoreCase("Stereo")) {

                Stero.settyposMetaforas();
               Stereo.gettyposMetaforas();
       }
             System.out.println("Grapste Ygro");
            if ((Typos = UserInput.getString()).equalsIgnoreCase("Ygro")) {
                Ygro.settyposMetaforas();
                Ygro.gettyposMetaforas();
       }
             System.out.println("Grapste Aerio");
            if ((Typos = UserInput.getString()).equalsIgnoreCase("Aerio")) {
                Aerio.settyposMetaforas(3);
                Aerio.gettyposMetaforas(3);
       } System.out.println("Grapste Meikto");
            if ((Typos = UserInput.getString()).equalsIgnoreCase("Meikto")) {
                Meikto.settyposMetaforas(4);
                Meikto.gettyposProiontos(4);
       }
       }

    }

2 个答案:

答案 0 :(得分:0)

您的构造函数签名必须匹配。 Metafores抽象类具有:  (int,int,int,int,double) 而子类签名是:  (String,int,int,int,String,double)

获取所有构造函数参数以匹配每个类。

答案 1 :(得分:0)

您的构造函数没有相同的类型。更新构造函数参数,并确保参数必须是相同的类型。

Aerio扩展了Metafores

public Aerio(int SyskeuasiaAeriou,int gettyposProiontos,int gettyposMetaforas,int gettyposMetrisis,String getonomaProiontos,double gettimiMonadas){ }

Meikto扩展了Metafores

public Meikto(String perigrafhSyskeuasias,int gettyposProiontos,int gettyposMetaforas,int gettyposMetrisis,String getonomaProiontos,double gettimiMonadas){ }

公共课Stereo扩展了Metafores

public Stereo(String perigrafhYlikou,int gettyposProiontos,int gettyposMetaforas,int gettyposMetrisis,String getonomaProiontos,double gettimiMonadas){ }

Metofores抽象类是:

 public Metafores(int gettyposProiontos,int gettyposMetaforas,int gettyposMetrisis,int getonomaProiontos,double gettimiMonadas){}