Can abstract method be overridden

"An abstract method can be overridden by an abstract method"
If an abstract method does not have any implementation, then what does one mean by overriding an abstract class in the subclass. Any code to show this will be of better understanding.
Thanks..

As yawmark demonstrated it can be use to to increase visibilty but it can also be used to reduce exception declarations.
Example:
abstract class A
    abstract void f() throws java.io.IOException, java.sql.SQLException;
abstract class B extends A
    abstract void f() throws java.net.SocketException;   
}

Similar Messages

  • Can Static Methods be overridden ?

    My question is can static methods be overridden ?
    I found this thread [Can Static Method be overridden ?|http://forums.sun.com/thread.jspa?threadID=644752&start=0&tstart=0] .Since it was too old,i have created this new thread.
    According to that thread discussion, Java language states that static methods cannot be overridden.
    To which kajbj posted a program which did allow overriding of static methods.To quote him :
    I filed a bug report on it. I don't know if it's expected behaviour or not, but I expect the compiler to complain if you add @Override to a static method (since it can't be overridden)
    /Kaj This is one small program code which i wrote ,which did not allow static methods to be overridden,but no error as such was displayed.
    package fundamentals;
    class SuperClass
      public static String getName()
           return "HI,CLASS...SUPER CLASS";
      public int getAge()
           return 20;
    } // END OF SUPER CLASS
    public class SubClass extends SuperClass{
    public static void main(String[] args)
              SubClass objSubClass=new SubClass();
              SuperClass objSuperClass=new SubClass();
              System.out.println(objSubClass.getName());      // SUB CLASS
              System.out.println(objSuperClass.getName());   // SUPER CLASS
              System.out.println(objSubClass.getAge());        // SUB CLASS
              System.out.println(objSuperClass.getAge());     // SUPER CLASS
                     public    static String getName()
                       return "HI,CLASS...SUB CLASS";
                     public int getAge()
                        return 40;
    } // END OF MAIN CLASSWhich gives the O/P :
    HI,CLASS...SUB CLASS
    HI,CLASS...SUPER CLASS
    40
    40So,the static method was not overridden.
    But ,why was no error message displayed ?
    Also when i modify the subclass static method,by removing the static keyword as follows :
    public  String getName()
                       return "HI,CLASS...SUB CLASS";
                     }A Error Message as :
    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
         This instance method cannot override the static method from SuperClassis displayed.
    Why this message is displayed after i remove the static keyword ?
    So can we say that Java does not allow static method to be overridden but does not display a compile/run time error when this is done ?
    Is this a bug as stated by kajbj ?
    Please let me know if i am not clear.If this question has been answered somewhere else in this forum,kindly let me know.
    Thank you for your consideration.

    amtidumpti wrote:
    My question is can static methods be overridden ?
    I found this thread [Can Static Method be overridden ?|http://forums.sun.com/thread.jspa?threadID=644752&start=0&tstart=0] .Since it was too old,i have created this new thread.
    According to that thread discussion, Java language states that static methods cannot be overridden.
    To which kajbj posted a program which did allow overriding of static methods.To quote him :
    I filed a bug report on it. I don't know if it's expected behaviour or not, but I expect the compiler to complain if you add @Override to a static method (since it can't be overridden)
    /Kaj
    Sigh! Amti, are you being misleading on purpose? Kaj did not "post a program which did allow overriding of static methods." He posted a program which used the annotation @Override on a static method, like this:
    class A {
        public static void m() {}
    class B extends A {
        @Override public static void m() {}
    }He wondered why it didn't generate an error message. Well, it does now:
    A.java:6: method does not override or implement a method from a supertype
        @Override public static void m() {}
        ^
    1 error

  • Static abstract methods - how can I avoid them?

    Hi everybody,
    just found out that java doesn't allow static abstract methods nor static methods in interfaces. Although I understand the reasons, I can't think of how to change my design to gain the required behavior without the need of static abstract methods.
    Here's what I want to do and how my thoughts lead to static abstract methods:
    ClassA provides access to native code (c-dll, using jna). The path to the dll can be set programmatically. Here's a draft of the class:
    public ClassA {
       private static String path;
       public static void setRealtivePath(String path) {
          //check if path exists and is not null -> get absolute path
          setPath(path);
       public static void setPath(String absolutePath) {
          this.path = path;
      //code to provide access to native lib
    }There is some more classes which provide access to different dlls (therefore the code for accessing the dlls differs from ClassA). Although this works, the setRelativePath method has to be implemented in each class. I thought it would be nice to put this method into a abstract super class that looks like this:
    public abstract class superClass {
       public static void setRelativePath(String path) {
          //check if path exists and is not null -> get absolute path
          setPath(path);
       //force inherting class to implement a static method
       public static abstract void setPath(String absolutePath);
    }thus simplifying ClassA and it's look-a-likes:
    public ClassA {
       private static String path;
       @Override
       public static void setPath(String absolutePath) {
          this.path = path;
      //code to provide access to native lib
    }Since static abstract methods (and overriding static methods) is not allowed, this doesn't work.
    I hope someone can catch my idea ;). Any suggestions how to do this in a nice clean way?
    Thanks in advance,
    Martin
    Edited by: morty2 on Jul 22, 2009 2:57 AM

    First of all, thanks a lot for your answer.
    YoungWinston wrote:
    Actually, you can "override" static methods (in that you can write the same method for both a subclass and a superclass, providing the superclass method isn't final); it's just that it doesn't work polymorphically. The "overriding" method masks the overridden one and the determination of what gets called is entirely down to the declared type.Yes, I know that. There's one problem: Your suggestion means that I simply have to drop the abstract modifier in the super classes setPath method. However, since the super class calls the setPath method (and not the inherting classes!) it will always be the super classes' method being called.
    YoungWinston wrote:
    Why are you so concerned with making everything static? Seems to me that the simplest solution would be to make all the contents instance-based.I want ClassA and it's look-a-likes to be set up properly at application start up, be accessible quite anytime and easily, they don't do anything themselves except for setting the path and calling into the native library which does the math. (Compareable to how you call e.g. Math.cos()). Therefore I don't think that an instance-based solution would be a better approach.
    YoungWinston wrote:
    Furthermore, you could make the class immutable; which might be a good thing - I'm not sure I'd want someone being able to change the pathname after I've >set up a class like this.Thanks for that!
    PS: As mentioned in my first post, I do have a working solution. However, I'm really corious about finding a nicer and cleaner way to do it!
    Martin

  • Can i call non -abstract method in abstract class into a derived class?

    Hi all,
    Is it possible in java to call a non-abstract method in a abstact class from a class derived from it or this is not possible in java.
    The following example will explain this Ques. in detail.
    abstract class A
    void amethod()
    System.out.println(" I am in Base Class");
    public class B extends A
    void amethod()
    System.out.println(" I am in Derived Class");
    public static void main (String args[])
    // How i code this part to call a method amathod() which will print "I am in Base Class
    }

    Ok, if you want to call a non-static method from a
    static method, then you have to provide an object. In
    this case it does not matter whether the method is in
    an abstract base class or whatever. You simply cannot
    (in any object oriented language, including C++ and
    JAVA) call a nonstatic method without providing an
    object, on which you will call the method.
    To my solution with reflection: It also only works,
    if you have an object. And: if you use
    getDeclaredMethod, then invoke should not call B's
    method, but A's. if you would use getMethod, then the
    Method object returned would reflect to B's method.
    The process of resolving overloaded methods is
    performed during the getMethod call, not during the
    invoke (at least AFAIK, please tell me, if I'm wrong).You are wrong....
    class A {
        public void dummy() {
             System.out.println("Dymmy in A");
    class B extends A {
         public void dummy() {
              System.out.println("Dymmy in B");
         public static void main(String[] args) throws Exception {
              A tmp = new B();
              Class clazz = A.class;
              Method method = clazz.getDeclaredMethod("dummy", null);
              method.invoke(tmp, null);
    }Prints:
    Dymmy in B
    /Kaj

  • Overridden methods  run like an abstract method

    public class Mammal
    public int length;
    public Mammal(int b)
    this.length=b;
    public void speciesName()
    System.out.println("I am a mammal");
    public class Cat extends Mammal
    public Cat (int b)
    super(b);
    public void speciesName()
    System.out.println("I am a Cat");
    public class Goat extends Mammal
    public Goat(int b)
    super(b);
    public void speciesName()
    System.out.println("I am a Goat");
    public class Test
    public static void main(String[] args)
    Cat k=new Cat(50);
    Goat g=new Goat(60);
    Vector<Mammal> v=new Vector<Mammal>();
    v.add(k);
    v.add(g);
    Mammal m; //reference
    m=v.elementAt(0);
    m.speciesName();
    m=v.elementAt(1);
    m.speciesName();
    hello all,
    my problem about above code is:
    on the console : I am a Cat
    I am a Goat
    but i did not understand why the result is so this.
    i thought that the screen output must be : I am a Mammal
    I am a Mammal
    i supposed that Mammal class's speciesName() method must run.
    if speciesName() was abstract method, i could understand the result.
    but in this situation, i didn't understand how the output is this.
    thanks...

    khanD wrote:
    i thought that the screen output must be : I am a Mammal
    I am a Mammal
    i supposed that Mammal class's speciesName() method must run.
    if speciesName() was abstract method, i could understand the result.
    but in this situation, i didn't understand how the output is this.Now you know that it doesn't matter whether speciesName in Mammal is abstract or not. Overriding works the same regardless.
    But there are other differences. For example right now Mammal is concrete so you could create a Mammal object if you wanted. If you made speciesName abstract that would no longer be possible. Right now you also don't have to override speciesName in the subclasses. If speciesName were abstract you would have to do that.

  • Abstract Method Overriding Problem

    I have an abstract class called "Employee" with an abstract method called "ReturnBasicInfo()" defined.
    I have two subclasses, SalariedEmployee and HourlyEmployee, and each has their own version of ReturnBasicInfo(). The compiler is not letting me do this, however, and I have no idea why.
    I keep getting this error:
    SalariedEmployee.java:6: SalariedEmployee is not abstract and does not override
    abstract method returnBasicInfo() in Employee.The abstract method signature is this:
    public abstract String returnBasicInfo(Employee e);Any idea why this might be happening? I have another abstract method called toVector() that's overriden in the subclasses and that one works fine, so I'm stumped on this. The only difference between the two is that this method takes arguments and the other doesn't. Is that why it can't be overriden?
    Thanks in advance for any help!

    "...In the instructor's example code, he actually
    overrode toString with this method. I thought I might
    be using the real toString(), though, so that's why I
    changed the name to returnBasicInfo(). I didn't end up
    using toString(), though. Maybe I ought to go back to
    calling it toString()..."
    Yes, this SHOULD be overridden in toString(). Do go
    back to it.
    The "real" toString()? Do you mean the default
    version in java.lang.Object, the one that just prints
    out the object reference when it's called?
    Hmm, I guess. I got confused because I'm swapping between String and double values a lot. Taking in an entered number as a String and converting it to a double.
    I think I originally confused toString() with String.valueOf().
    I wouldn't have getYearlySalary() for SalariedEmployee
    and getHourlySalary() for HourlyEmployee. That
    defeats the purpose of polymorphism and dynamic
    typing. Yes, but I do have one polymorphic method --pay(). Each Employee is paid a different way. The one method we were supposed to be able to call on all Employees is just pay(). There is one version of pay() for HourlyEmployees that uses gethourly_rate() and gethours_worked() to get hourly rate and hours worked. The other version of pay() in SalariedEmployees takes in their yearly salary and number of pay periods worked.
    Better to have a getSalary() method in your
    Employee interface and let each subclass implement it
    the way they want to. SalariedEmployee will return
    their yearly salary, HourlyEmployee will return
    hourlySalary*hoursWorkedOK, that's one idea.
    But darnit, I would still like to know how to get my original design to work. So I should change returnBasicInfo() to toString(), you think?

  • Virtual methods- abstract methods

    Hi, I need to get this clear in my head.
    In C++ you had virtual methods()
    If a method was virtual this made the enclosing class abstract.
    There is no such thing as abstract methods in C++?
    In java, if you have an abstract method your enclosing class becomes abstract.
    There is no such thing as a virtual method in java.
    is all the above correct?
    Thanks ... J

    Hi, I need to get this clear in my head.
    In C++ you had virtual methods()
    If a method was virtual this made the enclosing class abstract.
    There is no such thing as abstract methods in C++?Incorrect.
    Abstract methods have no implementation. You can have those in C++. If I remember correctly, they'd look something like this:
    public void foo() = 0;
    In java, if you have an abstract method your
    enclosing class becomes abstract.
    There is no such thing as a virtual method in java.Incorrect.
    All methods in Java are virtual by default. Every method is fair game to be overridden by a subclass. You mark them with the final keyword to prohibit overriding.
    All methods in C++ are final by default. You can't override any method in a subclass unless you mark it with the virtual keyword. (This was keeping the Bjarne's philosophy of "only pay for what you use".)
    %

  • ...is not abstract and does not override abstract method compare

    Why am I getting the above compile error when I am very clearly overriding abstract method compare (ditto abstract method compareTo)? Here is my code -- which was presented 1.5 code and I'm trying to retrofit to 1.4 -- followed by the complete compile time error. Thanks in advance for your help (even though I'm sure this is an easy question for you experts):
    import java.util.*;
       This program sorts a set of item by comparing
       their descriptions.
    public class TreeSetTest
       public static void main(String[] args)
          SortedSet parts = new TreeSet();
          parts.add(new Item("Toaster", 1234));
          parts.add(new Item("Widget", 4562));
          parts.add(new Item("Modem", 9912));
          System.out.println(parts);
          SortedSet sortByDescription = new TreeSet(new
             Comparator()
                public int compare(Item a, Item b)   // LINE CAUSING THE ERROR
                   String descrA = a.getDescription();
                   String descrB = b.getDescription();
                   return descrA.compareTo(descrB);
          sortByDescription.addAll(parts);
          System.out.println(sortByDescription);
       An item with a description and a part number.
    class Item implements Comparable     
          Constructs an item.
          @param aDescription the item's description
          @param aPartNumber the item's part number
       public Item(String aDescription, int aPartNumber)
          description = aDescription;
          partNumber = aPartNumber;
          Gets the description of this item.
          @return the description
       public String getDescription()
          return description;
       public String toString()
          return "[descripion=" + description
             + ", partNumber=" + partNumber + "]";
       public boolean equals(Object otherObject)
          if (this == otherObject) return true;
          if (otherObject == null) return false;
          if (getClass() != otherObject.getClass()) return false;
          Item other = (Item) otherObject;
          return description.equals(other.description)
             && partNumber == other.partNumber;
       public int hashCode()
          return 13 * description.hashCode() + 17 * partNumber;
       public int compareTo(Item other)   // OTHER LINE CAUSING THE ERROR
          return partNumber - other.partNumber;
       private String description;
       private int partNumber;
    }Compiler error:
    TreeSetTest.java:25: <anonymous TreeSetTest$1> is not abstract and does not over
    ride abstract method compare(java.lang.Object,java.lang.Object) in java.util.Com
    parator
                public int compare(Item a, Item b)
                           ^
    TreeSetTest.java:41: Item is not abstract and does not override abstract method
    compareTo(java.lang.Object) in java.lang.Comparable
    class Item implements Comparable
    ^
    2 errors

    According to the book I'm reading, if you merely take
    out the generic from the code, it should compile and
    run in v1.4 (assuming, of course, that the class
    exists in 1.4). I don't know what book you are reading but that's certainly incorrect or incomplete at least. I've manually retrofitted code to 1.4, and you'll be inserting casts as well as replacing type references with Object (or the erased type, to be more precise).
    These interfaces do exist in 1.4, and
    without the generics.Exactly. Which means compareTo takes an Object, and you should change your overriding method accordingly.
    But this raises a new question: how does my 1.4
    compiler know anything about generics? It doesn't and it can't. As the compiler is telling you, those interfaces expect Object. Think about it, you want to implement one interface which declares a method argument type of Object, in several classes, each with a different type. Obviously all of those are not valid overrides.

  • Getting error while creating abstract method

    hi folks,
    i facing issue for ABSTRACT Class.
    I am trying to create abstarct method, (refered example from saptechnical site),
    I created one attribute i-num, created one method AREA, in  implementation area , i made it as Abstract, then i did syntax check, then it is giving below error.
    *Class ZTEST_CLASS01_AB,Method AREA
    The abstract method "AREA" can only be implemented after its
    redefinition (METHODS AREA REDEFINITION).*
    i tried all the ways..
    created subclass for this, i writted some code in AREA of Sub-class, there it is giving dump, because first one is not activated properly..
    could you please somebody help me on this.
    Sri

    Hello Arshad,
    Create a class(ZABSTRACT) and make its type as Abstract( Which means atleast one of its methods is abstract)
    We can have abstract classes with all it's methods as non-abstract or concrete. A small example is given below:
    CLASS gcl_abstract DEFINITION ABSTRACT.
      PUBLIC SECTION.
        METHODS concrete. "Concrete
    ENDCLASS.                    "gcl_abstract DEFINITION
    *       CLASS gcl_abstract IMPLEMENTATION
    CLASS gcl_abstract IMPLEMENTATION.
      METHOD concrete.
        WRITE: / `I'm a concrete method`.
      ENDMETHOD.                    "concrete
    ENDCLASS.                    "gcl_abstract IMPLEMENTATION
    *       CLASS gcl_abstract_sub DEFINITION
    CLASS gcl_abstract_sub DEFINITION INHERITING FROM gcl_abstract.
      PUBLIC SECTION.
        METHODS concrete REDEFINITION.
    ENDCLASS.                    "gcl_abstract_sub DEFINITION
    *       CLASS gcl_abstract_sub IMPLEMENTATION
    CLASS gcl_abstract_sub IMPLEMENTATION.
      METHOD concrete.
        super->concrete( ).
        WRITE: / 'Abstract class might not have abstract methods at all!'.
      ENDMETHOD.                    "concrete
    ENDCLASS.                    "gcl_abstract_sub IMPLEMENTATION
    START-OF-SELECTION.
      DATA: go_abstract TYPE REF TO gcl_abstract_sub.
      CREATE OBJECT go_abstract.
      go_abstract->concrete( ).
    Although i will agree there is no point in making a class as abstract & having no abstract method
    @Sri: Looks like you're trying to implement the abstract method "AREA" in the abstract class hence the error. For abstract method you cannot define their implementation in the corres. abstract class.
    BR,
    Suhas
    Edited by: Suhas Saha on Mar 30, 2011 12:04 PM

  • ABAP OO Abstract Methods

    Hi,
    I want to use abstract methods in ABAP. I created an abstract class as base and another 'child' class that extends that class. Now, I want to have different implementations in different child classes. The problem is that the IDE redirects me to the base class when trying to to this. There is no possibility to set the method as abstract.
    Do you know if that concept is implemented at all? Maybe I just forgot to configure something?!
    What do you propose?
    Thank you and best regards,
    Daniel

    Hi,
    If you are creating Local class using SE38, then just by writing "abstact" to the method it behaves like an abstract method.
    If you are creating global class SE24, then genrally all interface methods are "abstract" methods so that we can ihberit and can redefine the methods for example: "IF_FLUSH_NOTIFY~BEFORE_FLUSH_NOTIFY" symbol ~ shows that it is an abstract method in the interface before to that.
    So, even if it refer to its base class you can just implement them in the child classes by inheriting it.
    Hope this helps you if yes try to assign some app. points.
    Regards,
    Suman

  • "Abstract" method in a non-abstract class

    Hi all.
    I have a class "SuperClass" from which other class are extended...
    I'd like to "force" some methods (method1(), method2, ...) to be implemented in the inherited classes.
    I know I can accomplish this just implementing the superclass method body in order to throw an exception when it's directly called:
    void method1(){
    throw new UnsupportedOperationException();
    }...but I was wondering if there's another (better) way...
    It's like I would like to declare some abstract methods in a non-abstract class...
    Any ideas?

    The superclass just models the information held by
    the subclasses.
    The information is taken from the database, by
    accessing the proper table (one for each subclass).??
    What do you mean by "models the information"?
    You should use inheritance (of implementation) only when the class satisfies the following criteria:
    1) "Is a special kind of," not "is a role played by a";
    2) Never needs to transmute to be an object in some other class;
    3) Extends rather than overrides or nullifies superclass;
    4) Does not subclass what is merely a utility class (useful functionality you'd like to reuse); and
    5) Within PD: expresses special kinds of roles, transactions, or things.
    Why are you trying to force these mystery methodsfrom the superclass?
    It's not mandatory for me to do it... I 'd see it
    just like a further way to check that the subclasses
    implements these methods, as they have to do.That's not a good idea. If the superclass has no relation to the database, it shouldn't contain methods (abstract or otherwise) related to database transactions.
    The subclasses are the classes that handle db
    transaction.
    They are designed as a binding to a db table.And how is the superclass designed to handle db transactions? My guess (based on your description) is that it isn't. That should tell you right away that the subclasses should not extend your superclass.

  • Non-abstract methods in a Abstract class

    Abstract Class can contain Non-abstract methods.
    and Abstract Classes are not instantiable as well
    So,
    What is the purpose of Non-abstract methods in a Abstract class.
    since we can't create objects and use it
    so these non-abstract methods are only available to subclasses.
    (if the subclass is not marked as abstract)
    is that the advantage that has.(availability in subclass)
    ??

    For example, the AbstractCollection class (in
    java.util) provides an implementation for many of the
    methods defined in the Collection interface.
    Subclasses only have to implement a few more methods
    to fulfill the Collection contract. Subclasses may
    also choose to override the AbstractCollection
    functionality if - for example - they know how to
    provide an optimized implementation based on
    characteristics of the actual subclass.Another example is the abstract class MouseAdapter that implements MouseListener, MouseWheelListener, MouseMotionListener, and that you can use instead of these interfaces when you want to react to one or two types of events only.
    Quoting the javadocs: "If you implement the MouseListener, MouseMotionListener interface, you have to define all of the methods in it. This abstract class defines null methods for them all, so you can only have to define methods for events you care about."

  • Abstract method versus static and non-static methods

    For my own curiosity, what is an abstract method as opposed to static or non-static method?
    Thanks

    >
    Following this logic, is this why the "public static
    void main" 0r "Main" method always has to be used
    before can application can be run: because it belongs
    to the class (class file)?
    Yes! Obviously, when Java starts up, there are no instances around, so the initial method has to be a static (i.e. class) one. The name main comes from Java's close association with C.
    RObin

  • Abstract method

    Say DfObject is an abstract class with one abstract method, generateHTML. Now there is another object called DfContainer which stores, in a HashTable, objects that are subclasses of DfObject, like DfText, DfList,...
    I have a method in DfContainer to put objects of type DfText, DfList, ... into a HashTable.
    Now, Say I have a method, getObject(), in DfContainer to return an object from the HashTable. I set my return type for the method to DfObject. So in getObject(), I cast the object returned from the Hash to DfObject.
    Is the type returned from the hash of type Object, or is it of the actual types stored in the HashTable, like DfText, DfList,...?
    If my method returns an object of type DfObject, and if I were to call the abstract method generateHTML(), which is defined differently in each subclass, will it call the appropriate method? Or will I need to cast it to DfText or DfList before being able to call the abstract method?
    Thanks,
    Moshe

    Say DfObject is an abstract class with one abstract
    method, generateHTML. Now there is another object
    called DfContainer which stores, in a HashTable,
    objects that are subclasses of DfObject, like DfText,
    DfList,...
    I have a method in DfContainer to put objects of type
    DfText, DfList, ... into a HashTable.
    Now, Say I have a method, getObject(), in DfContainer
    to return an object from the HashTable. I set my
    return type for the method to DfObject. So in
    getObject(), I cast the object returned from the Hash
    to DfObject.
    Is the type returned from the hash of type Object, or
    is it of the actual types stored in the HashTable,
    like DfText, DfList,...?Lets say you add a DfText object to the Hashtable. When it comes out again you get an Object, but under this disguise it is still a DfText object so you are allowed to cast it into a DfObject or a DfText.
    >
    If my method returns an object of type DfObject, and
    if I were to call the abstract method generateHTML(),
    which is defined differently in each subclass, will it
    call the appropriate method? Or will I need to cast it
    to DfText or DfList before being able to call the
    abstract method?No you can just cast it to DfObject and invoke any methods in that class even if they are abstract. Its called dynamic method invocation or something.

  • Abstract method which when implemented will have different parameters

    Hello to all,
    I have an assignment but not looking for someone to do it for me. I am only searching for a suggestion on how to do the following.
    Imagine having an application that needs to provide an estimate of the rent for different buildings.
    Basically I start with by having a class name Building. This class has an abstract method called estimateRent.
    I then create two classes that extend the class Building which are named Apartment and House. Both need to have the method estimateRent.
    However the problem is that the rent for the Apartment is calculated on the nights passed in the flat and the people in it, while the rent for the House is just calculated on a month bases.
    This means the estimateRent method requires to have different parameters depending if it is implemented inside the Apartment class or the House class.
    Now I only know of two options.
    The first option is to not declare the estimateRent method as an abstract method inside the Building class and just implemented inside the Apartment and House with different parameters. I do not like this option since in the future if a new Building comes in then I would like to impose the fact that that object needs to have a calculate method.
    The second option is to make the estimateRent method as abstract inside the Building class however takes a parameter of either a String array or else a Map. Then the estimateRent within the Apartment class would search for the elements tagged as nights and people, and the House class would only search for the elements tagged as months!
    However do not know if there are any other, better ways on how to do this. I am using Java 1.4 however if you only have answers for Java 5.0 then please post them again since I always like to learn something new :)
    Thank You for any comments.
    tx

    The implementation changes, yes.Yes that I could understand in the Strategy Pattern (in the document I read it was being compared with the Template Pattern).
    Then you need to refactor your design.I tought about that, however if you read my first post you will notice that I have different criteria on which the costs need to be estimated. While the costs for a flat are estimated on the people staying in and nights slept there, the costs for the house are based only on the months stayed there regardless of the people living in. Now for me I feel that it is bad programming practice to create one method that can have all the parameters required for any scenario. I mean the following is NOT something I am going to do:
    estimateCosts(int nights, int people, int months ... etc);
    That's not a very elegant way of going about it.
    What is the "Context" going to have?Yep I agree, but so far my limited brain has only come up with that! I am open to any other sugestion! always if i understand it first!
    Basically the Context would better be named as Criteria and it would be an interface as follows:
    interface Criteria{}
    Then I would create two classes that implement the Criteria object as follows:
    class AppartmentCriteria implements Criteria{
    public Result estimateCosts(int nights, int people);
    class HouseCriteria implements Criteria{
    public Result estimateCosts(int months);
    Now when I recieve the inputs, depending on the scenario the Criteria is typecasted and the correct parameters passed and we recieve the Result.
    I feel the above sucks since I am not seeing it as an object oriented way of doing this out! Is there any other sugestions! The refactoring thing I am intrested in! however really I can not see how such a call to that method could be refectored!
    Thank You,
    tx.
    PS: Sun has blocked my other account as well, and this time they did not even send me an email to confirm that I was registered successfuully :( Is there someone I can contact on this? I guess next time I will reply with tx53m :)

Maybe you are looking for

  • What's the purchase order agreement master data table name?

    hi experts what's the the purchase order agreement master data table name? and by the way tell me some relative table about agreement. thanks a lot and hunger for ur advice.

  • Can't kill remote objects!

    OK, from what i've read and seen, there are 4 things that must happen in order to successfully release a server-side remote object and have it garbage-collected: 1) The server must call unexportObject 2) The client must release all references (stubs)

  • Weblogic 10.3 - Windows 2003 64bit OS

    I cannot find the download .exe for the 64bit version of Weblogic Server 10.3 and Portal. Is there a seperate download or do I install the 32bit version on the server? I called the 800 number but was transferred and then dropped - twice!! Any help is

  • P/r release

    Dear All, in PR we have confighure two release indicator that is A and B, A for head of the dept. and B for management  lavel, but in me54n it is allowing to release both (A,B) , we want to block it user wise, is it possible, please give sollution re

  • Enhance errors OS10...3.1

    Hello BlackBerry Support Community Forums I will provide two images With official OS10.3.1565 for Z10 Clearly the application "Games" still appears after the upgrade. When this application services do not work, and BlackBerry to inform would removed