Issue
I have a class that implements an interface that extends from autocloseable. My doubt is, only the methods from my interface will be autocloseable or the methods from my class (and not from the interface) will be autocloseable too?
Solution
I think you may be confused about inheritance.
interface MyInterface{
void method();
}
class Super implements MyInterface{
/* must be implemented. If it's not, then it would NOT also be a MyInterface type */
public void method(){ ... }
}
class SubClass extends Super {
// if nothing is added, then only the methods from Super will be a part of SubClass.
// that means method() is part of this class.
// It also implements MyInterface, because Super does.
}
So you can call method like this:
// SubClass is a SubClass type, a Super type and a MyInterface type
MyInterface test = new SubClass();
test.method();
The AutoCloseable
interface only has one method void close()
and that has to be implemented by any class that directly declares implements AutoClosable
. Every class that inherits from that class is also an AutoClosable
type and automatically has an implemented public close()
method.
Answered By - Scratte
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)