Home > Mobile >  Defining abstract interface methods
Defining abstract interface methods

Time:10-15

If you create an abstract child of an abstract parent that implements an interface do you need to define the abstract interface methods in that child?

if I can get an example of this in code that would be helpful thank you!

CodePudding user response:

No. When your child class is abstract, you don't need to implement the abstract methods of the parent.

Since your child is abstract, it can't be instantiated.

CodePudding user response:

Short answer: No.

Long answer like the ones your lecturer (or mine) would give you:

Assume we have an interface, AbstInter with some functions:

public interface AbstInter {
    void funct1();

    String funct2();
}

And then a class that implements it:

public abstract class AbstParent implements AbstInter {
    public int funct3() {
        return 1;
    }
}

And a child class that extends the previous class:

public abstract class AbstChild extends AbstParent {
    // nothing here for now
}

The IDE would not give me any errors.

  •  Tags:  
  • java
  • Related