Week 9 Activity
Week 9 Activity
Tutorial Activity: 9
Abstract class and interface both are used to achieve abstraction where we
can declare the abstract methods. Abstract class and interface both can't be
instantiated.
But there are many differences between abstract class and interface that are
given below.
1) Abstract class can have abstract and non- Interface can have only
abstract methods. abstract methods. Since Java 8, it can
have default and static methods also.
3) Abstract class can have final, non-final, Interface has only static and final
static and non-static variables. variables.
6) An abstract class can extend another Java An interface can extend another Java
class and implement multiple Java interfaces. interface only.
8) A Java abstract class can have class Members of a Java interface are public
members like private, protected, etc. by default.
9)Example: Example:
public abstract class Shape{ public interface Drawable{
public abstract void draw(); void draw();
} }