Abstract Method In Abstract Class In java

WLA

Is it possible in Java? Or can I use any method before define it?

I tried it in Abstract class but JVM said abstarct method can't be static. Then I tried define class to object but i did not use 'extends'. Both of them gave me a error.

STaefi

Yes it's possible to call an abstract method before defining it in the abstract class. Assume you have designed a base formula class:

public abstract class AbstractFormula {

    protected abstract void initialize();

    public double evaluate() {
        initialize();
        //
        // do the logic
        //
        return 0d; // the result
    }
}

Also assume the logic for evaluating formula is to:

  1. initialize the coefficients
  2. do the math to calculate the result

So the default implementation of the evaluate() method is to call the initialize() method and then do the calculation. In other word, you may not know the logic of initializing coefficient in all possible implementations of AbstractFormula, but you can call it in other methods of the abstract class.

But you can NOT create a static abstract method in the first place. Because static methods are class methods and can be called without creating a object of that class. So having an static abstract method is pointless. static methods should have their body when they are being defined.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Class is not abstract and does not override abstract method error

From Java

Class is not abstract and does not override abstract method

From Java

Java how to optional override method in abstract class?

From Java

Java override non abstract method as abstract in extended class

From Java

Java final abstract class

From Java

Is a Java interface an abstract class?

From Java

Java abstract class and interface

From Java

Is it valid to call an abstract method on the super class in java

From Java

ClickableSpan - Class is not abstract and does not override abstract method

From Java

Class is not abstract and does not override abstract method in superclass

From Java

Java abstract class, abstract constructor

From Dev

Java constructor of an abstract class

From Dev

What is the purpose of internal abstract method in a abstract class?

From Dev

Protected abstract or public abstract method in abstract class

From Dev

Java - abstract class and interface

From Dev

Abstract class method declaration

From Dev

Is the abstract method in the interface Inter is same with the abstract method in the abstract class Test?

From Dev

Abstract Class must override an abstract method?

From Dev

Using an overridden method from an abstract class (Java)

From Dev

Is it compulsory to declare abstract class for abstract method?

From Dev

Java Overriding abstract class method with an interface as param

From Dev

Java - Calling method from child of abstract class

From Dev

Use of an abstract class in Java

From Dev

Creating a method for an abstract class in java

From Dev

Java abstract class generic method parameter

From Dev

partial implementation of abstract method of an abstract class

From Dev

java call method in constructor and abstract class?

From Dev

Abstract method in a non abstract class

From Dev

How to call non abstract method in a abstract class?

Related Related

  1. 1

    Class is not abstract and does not override abstract method error

  2. 2

    Class is not abstract and does not override abstract method

  3. 3

    Java how to optional override method in abstract class?

  4. 4

    Java override non abstract method as abstract in extended class

  5. 5

    Java final abstract class

  6. 6

    Is a Java interface an abstract class?

  7. 7

    Java abstract class and interface

  8. 8

    Is it valid to call an abstract method on the super class in java

  9. 9

    ClickableSpan - Class is not abstract and does not override abstract method

  10. 10

    Class is not abstract and does not override abstract method in superclass

  11. 11

    Java abstract class, abstract constructor

  12. 12

    Java constructor of an abstract class

  13. 13

    What is the purpose of internal abstract method in a abstract class?

  14. 14

    Protected abstract or public abstract method in abstract class

  15. 15

    Java - abstract class and interface

  16. 16

    Abstract class method declaration

  17. 17

    Is the abstract method in the interface Inter is same with the abstract method in the abstract class Test?

  18. 18

    Abstract Class must override an abstract method?

  19. 19

    Using an overridden method from an abstract class (Java)

  20. 20

    Is it compulsory to declare abstract class for abstract method?

  21. 21

    Java Overriding abstract class method with an interface as param

  22. 22

    Java - Calling method from child of abstract class

  23. 23

    Use of an abstract class in Java

  24. 24

    Creating a method for an abstract class in java

  25. 25

    Java abstract class generic method parameter

  26. 26

    partial implementation of abstract method of an abstract class

  27. 27

    java call method in constructor and abstract class?

  28. 28

    Abstract method in a non abstract class

  29. 29

    How to call non abstract method in a abstract class?

HotTag

Archive