declaring abstract method that receives different parameters

i want to declare an abstract method, just formality since i can declare them with the same name in inherit classes without declaring the abstract in parent, anyway, the problem is that according to subclass type, it must receive different parameters. in both cases they are enum values, but different types of enums for each subclass. i can not declare a 'void' parameter, i dont know if i can declare for example a casting in a declaration, like:

in parent

abstract something(int someparam)

in subclass

something ((int) enumtype someparam)

is this possible



Answer this question

declaring abstract method that receives different parameters

  • *Elad*

    First I must repeats the others' statement that your design is not of much use, but nevertheless, this should work:



    abstract class Aparams {}
    abstract class A
    {
    abstract int something (Aparams p);
    }

    class B: A
    {
    int something (Aparams p)
    {
    BParams bp = p as Bparams;
    // uses bp.e here
    }
    }

    class C: A
    {
    int something (Aparams p)
    { /* as above */}
    }

    class Bparams :Aparams
    {
    public BEnum e;
    }
    class Cparams :Aparams
    {
    public CEnum e;
    }



  • Isaac Brock

    Hi,
    I didn't understand very well your question but I guess that you're asking if you can cast the enum types to int's and the answer is yes, you can cast enum types to int.


  • TheMaj0r

    So what's the point of having the method in the base class If the methods in the derived classes take different parameters you can't take advantage of polymorphism anyway.



  • pradeep990

    Hi when you want to override a abstarct method in the derived class, its signature and type should be the same. You cant change it as and when required. The compiler throws an error.
  • declaring abstract method that receives different parameters