Escolar Documentos
Profissional Documentos
Cultura Documentos
Example :
1.public interface Television Remote {
public void turnOnTelevision();
public void turnoff Television();
2.}
Syntax: –
Abstract classes are created using abstract keyword and they may have or may not have method
implementation. If a method is declared abstract then its implementation has to be provided by the class
extending the abstract class. We can have abstract class without abstract method as well as they can
contain final methods also. A class that extends the abstract class is a child class for that abstract class
and has to provide implementation for the abstract method declared in the abstract class.
Now question must be arising why we have interfaces and abstract classes. There are
few key differences worth noticing : –
1.Interfaces are implicitly abstract and cannot have implementations. Abstract classes
can have method implementations.
Copyright @ 2019 Learntek. All Rights Reserved. 11
2.Variables of interfaces are final by default. Abstract classes may or may not have
final variable.
3.Interface methods are public whereas abstract classes can provide all types of
access modifiers for its members i.e., public, protected, private.
4.Interface can extend interface only while classes can implement multiple interfaces
and can extend one class only.
Thus, both abstract classes and interfaces are used to achieve abstraction and both
have their own importance while designing a java solution but most preferable
choice for most developers is to use interfaces as they provide complete abstraction.
I hope this article helps to clear your doubts regarding abstraction.
12
Copyright @ 2019 Learntek. All Rights Reserved.
For more Training Information , Contact Us
Email : info@learntek.org