BABA GHULAM SHAH BADSHAH UNIVERSITY (RAJOURI)
AJEELA MUSHTAQ
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
OUTLINE :
• INHERITANCE
• TYPES
• INTERFACES
DEFINING AN INTERFACE
EXTENDING AN INTERFACE
IMPLEMENTING INTERFACES
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.
Types
• Single inheritance:
A derived class with only one base class is
called single inheritance.
• Multiple inheritance:
A derived class with several base classes is
called multiple inheritance.
• Multi-level inheritance:
The mechanism of deriving a class from
another ‘derived class’.
• Hierarchical inheritance:
A derived class in which the traits of one
class may be inherited by more than one class.
• 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:
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.
• Syntax
interface interfacename
member declarations
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
• 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.
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
• 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
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 () );
Output
sum = 30
product = 200
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.
Thank you…!
Have a nice day
19

Interfaces .net

  • 1.
    BABA GHULAM SHAHBADSHAH UNIVERSITY (RAJOURI) AJEELA MUSHTAQ
  • 2.
    BABA GHULAM SHAHBADSHAH 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 mechanismof 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.
  • 5.
    Types • Single inheritance: Aderived class with only one base class is called single inheritance.
  • 6.
    • Multiple inheritance: Aderived class with several base classes is called multiple inheritance.
  • 7.
    • Multi-level inheritance: Themechanism of deriving a class from another ‘derived class’.
  • 8.
    • Hierarchical inheritance: Aderived class in which the traits of one class may be inherited by more than one class.
  • 9.
    • This iscombination 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 interfacecan 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.
  • 11.
  • 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 areallowed 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 • Interfacesare 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 theclass 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 intAdd (); 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 () );
  • 17.
  • 18.
    Properties…. • All themembers 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.
  • 19.