2. BABA GHULAM SHAH BADSHAH
UNIVERSITY- RAJOURI (J&K).
DEPARTMENT OF COMPUTER
SCIENCES
PRESENTATION TOPIC:-
PRESENTED BY:-
Ajeela Mushtaq Roll NO:-13-Mcs-15
PRESENTED TO:-
MR MIRZA WASEEM
INTERFACES
3. OUTLINE :
• INHERITANCE
• TYPES
• INTERFACES
DEFINING AN INTERFACE
EXTENDING AN INTERFACE
IMPLEMENTING INTERFACES
4. Inheritance
• The mechanism of deriving a new class from an old one
is called inheritance.
• The old class is referred to as the base class and the
new one is called the derived class or sub-class.
• A derived class can inherits some or all of the traits
from the base class.
8. • Hierarchical inheritance:
A derived class in which the traits of one
class may be inherited by more than one class.
9. • This is combination of more than one inheritance.
• Hence, it may be a combination of Multilevel and
Multiple inheritance or Hierarchical and Multilevel
inheritance or Hierarchical , Multilevel and Multiple
inheritance.
Hybrid inheritance:
10. INTERFACE
• An interface can contain one or more
methods,properties,indexers and events but none of
them are implemented in the interface itself.
• It is the responsibility of the class that implements the
interface to define the code for implementation of these
members.
12. EXTENDING AN INTERFACE
• Like classes, interfaces can also be extended. That is,
an interface can be subinterfaced from other interfaces.
• The new subinterface will inherit all the members of the
superinterface in the manner similar to subclasses.
interface name2 : name1
members of name2
13. • Interfaces are allowed to extend other interfaces,
subinterfaces cannot define the methods declared in
the superinterfaces.
• It is the responsibility of the class that implements the
derived interface to define all the methods.
• It is important to remember that an interface cannot
extend classes.
14. IMPLEMENTING INTERFACES
• Interfaces are used as ‘superclasses’ whose properties
are inherited by classes.
• It is therefore necessary to create a class that inherits
the given interface.
class classname : interfacename
body of classname
15. • Here the class classname ‘implements’ the interface
interfacename. a more general form of
implementation may look like this :
class classname : superclass, interface1,
interface2….
body of class name
This shows that a class can extend another class while
16. using system;
interface Addition
int Add ();
interface Multiplication
int Mul ();
Class Computation : Addition, Multiplication
int x, y;
public Computation(int x, int y) //constructor
this.x = x;
this.y = y;
Public int Add () // implement Add ()
return (x + y);
Public int Mul () // implement Mul ()
return (x * y);
Class InterfaceTest1
public Static void Main()
computation com = new computation (10,20);
Addition add = (Addition) com;
//casting
Console.WriteLine (“Sum = “ + add.Add () );
Multiplication mul = (Multiplication) com;
//casting
Console.WriteLine(“Product = “ + mul.Mul () );
18. Properties….
• All the members of an interface are implicitly public
and abstract.
• An interface cannot contain constant fields ,constructors
and destructors.
• Its members cannot be declared static.
• Since the method in an interface are abstract, they do
not include implementation code.
• An interface can inherit multiple interfaces.