Abstract Class:
Abstract class can have abstract and non-abstract methods.
Abstract class doesn't support multiple inheritance.
Abstract class can have final, non-final, static & non-static variable.
Abstract class can have static methods, main method and constructors.
Abstract class can provide the implementation of interface.
public abstract class Shape
{
public abstract void shape();
}
A Java abstract class can have instance methods that implements a default behavior.
An abstract class may contain non-final variable.
An abstract class can extend another Java class & implement multiple Java interfaces.
Java abstract classes are faster than interface.
Interface:
Interface can have only abstract method.
Interface support multiple inheritance.
Interface has only static & final variable.
Interface can't have static methods main method or constructor.
Interface can't provide the implementation of abstract classes.
public interface Drawable {
void draw();
}
Method of Java interface are implicitly abstract & cannot have implementation.
Java interface should be implemented using keyword "implements".
Java class can implements multiple interface.
In comparison with java abstract classes, java interface are slow as it requires extra indirection.
Subscribe to:
Post Comments (Atom)
Methods in JAVA Language
In general, a way may be thanks to perform some task. Similarly, the tactic in Java may be a collection of instructions that performs a sel...
-
Write a program that declares a structure Book to store BookId, book name and price. it declares another structure Order that contains Or...
-
An Object represents an entity within the world like someone, thing or concept etc. An object is identified by its name. An object...
-
Write a program that displays the sum of the following series using do-while loop. 1+ 1/4 + 1/8 + ........ + 1/100 S...
No comments:
Post a Comment
If you have any doubt please let me know