Abstract class Vs Interface
Sr No. | Abstract Class | Interface |
1 | Abstract has both Abstract and non-Abstract methods. | Interface only have Abstract methods. |
2 | It have final,non-final,staticand non-static variables. | It have only Final and Static variables. |
3 | It is Declare Using Abstract Keyword. | It is Declare Using Interface Keyword. |
4 | Abstract Class Extends Another Java Class. | Interface Extends only Java Interface only. |
5 | It can be extends using “extends” keyword. | It can be implements using “implements” keyword. |
6 | Abstract class has class members to be private and protected. | Interface has class members by default public only. |
7 | It Doesn't support Multiple inheritance. | It support multiple inheritance. |
8 | Example:
public abstract class demo{
|
Example:
public interface Demo{
|
Abstract class
A Java abstract class is a class which cannot be instantiated, meaning you cannot create new instances of an abstract class.
Declaring an Abstract Class in Java
public abstract class MyAbstractClass
{
}
Interface in java
An Interface is basically a kind of class. Like classes , interface has variables and methods but with some major differences.
The differences is that interface have :-
- Abstract and Final Methods and
- Abstract and static variables.
Syntax:-
interface Interfacename
{
variables declaration;
Methods decalaration;
}
Related Posts |
Abstract class in Java | Java For Beginner | Java Example | Java Basic. |
Interface in Java | Creation and Implementation | Abstract and final methods | Java for beginner. |
1 Comments
Well Placed All Points...👍👍👌👌👌
ReplyDelete