简体   繁体   中英

Defining abstract interface methods

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!

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM