Search This Blog

27 June, 2011

Interfaces : Java specific


• Java’s first route to multiple inheritance is
provided through interfaces.


• Usually, in multiple inheritance one is interested
only in the methods, and not in duplicate
inheritance of data members.


• An interface contains only
– constants (i.e., final data members), and
– method declarations
– Like a class the interface itself can have
default or public access.


access_type interface i_name
{
return_type method1(param_lst);
return_type method2 (param_lst);
type final var_name1 = value;
...
}


• However, all methods and constants in an
interface are implicitly public.


• A class implements an interface.
– i.e., the class defines the methods
declared in the interface.

– all interface methods must be declared
public in the class implementation.
• A class may implement more than one interface,
by providing a comma separated list of
interfaces.
access class class_name [extends
superclass_name] implements
interface_name1, interface_name 2
{...
]
• If a class which implements an interface, does
not implement all the methods of that interface,
then the class must be declared as abstract.


• Any subclass must either implement all the
methods or be itself declared as abstract.


• Interfaces thus provide a form of multiple
inheritance, in which a class may inherit
methods from a variety of sources.


------------------------------------------
Dynamic polymorphism, extending interfaces and adapter classes
------------------------------------------

No comments:

Post a Comment

Meetme@