If class is declared abstract then why abstract keyword used before method in abstract class?

In abstract class we declare whole class as abstract i.e incomplete then why abstract keyword needs to declare before method?


6 Answers
1-6 of  6
6 Answers
  • An abstract keyword is used before method in abstract class before abstract class have an abstract method but the normal or simple class cannot have an abstract method, so only for those methods which are without body, we can use an abstract keyword before method for abstract methods

  • Abstract class is a basic word of the keyword. It is use ful for the students

  • A class that is declared using “abstract” keyword is known as abstract class. It can have abstract methods(methods without body) as well as concrete methods (regular methods with body). A normal class(non-abstract class) cannot have abstract methods. In this guide we will learn what is a abstract class, why we use it and what are the rules that we must remember while working with it in Java.

  • Requires to extend this class. Its subclasses if not declared abstract again, can be instantiated.

  • abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.
    An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon), like this:
    abstract void moveTo(double deltaX, double deltaY);
    If a class includes abstract methods, then the class itself must be declared abstract, as in:
    public abstract class GraphicObject { // declare fields // declare nonabstract methods abstract void draw(); }
    When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, then the subclass must also be declared abstract.

  • An abstract method adds the incompleteness to class, thus compiler wants to declare whole class abstract. The only way to use an abstract class in your application is to extend this class. Its subclasses if not declared abstract again, can be instantiated.

Core Java

Didn't get the answer.
Contact people of Talent-Core Java directly by clicking here