

This is a fundamental concept in Object Oriented Programming. Hiding an implementation is often called an encapsulation. Wrapping up of data and methods is called Encapsulation. Because they share the same Interface definition, the control panel application does not need to know if they are polling monitors or real-time monitors because, from the control panel's point of view, it does not matter This is the "NetworkMonitor" interface and all network monitors will share this interface, but they may have a class heirarchy that is very different, for example, port-monitors may all fork a thread that periodically checks whereas our control panel interface just asks for the most recent answer hardware monitors may ask for their data in real-time or over RPC and thus have no need of inheriting from Thread. The interface to our main control panel is always the same: We need some means to poll the monitor object for an answer. Our monitors might check for web pages, or they may check for other ports, or they may have hooks for hardware checks. For example, let's say we have an application that monitors a network of computers. "Interface" is the Java way to do multiple inheritance, or a better way to think of it is as a way to design plug-ins. Ix.An abstract class inherits from Object and includes methods such as clone() and equals(). Viii.An abstract class can have any visibility: public, protected, private or none (package).Īn interface's visbility must be public or none (package). Vii.An abstract class can define constructor. Vi.An abstract class can have instance variables. All methods of an interface are abstract. V.An abstract class can have nonabstract methods. Iv.A class can implement any number of interfaces, but subclass at most one abstract class. Interfaces contain no implementation code.

Iii.Abstract classes may have some executable methods and methods left unimplemented. Ii.Java supports multiple interface inheritance, but only single implementation inheritance.

An abstract class provides not just an interface, it also provides a (partial) implementation. I.A Java interface is just that, a purely abstract method interface with no implementation component.

1) Difference between Abstract class and Interface?
