Historical philosophical, theoretical, and legal foundations of special and i...
abstract class and interface.Net
1. DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
BABA GHULAM SHAH BADSHAH UNIVERSITY RAJOURI
NAME:-lucky
ROLL NO. -------MCS-20-----
PRESENTATION TOPIC:- Abstract Class, Interface
PRESENTED TO:- Mr. -------
1
3. ABSTRACT CLASS
Abstract classes are one of the essential behaviors
provided by .NET.
Commonly, we would like to make classes that only
represent base classes, and don’t want anyone to
create objects of these class types.
We can make use of abstract classes to implement
such functionality in C# using the modifier 'abstract'.
An abstract class means that, no object of this class
can be instantiated, but can make derivations of
this.
3
4. FEATURES:
An abstract class can inherit from a class and one
or more interfaces.
An abstract class can implement code with non-
Abstract methods.
An Abstract class can have modifiers for methods,
properties etc.
An Abstract class can have constants.
4
5. CONT.….
An abstract class cannot be instantiated.
An abstract class contain abstract members as well
as non- abstract members.
An abstract class cannot be sealed class because
the sealed modifier prevents a class from being
inherited and the abstract modifier requires a class
to be inherited.
An abstract class can have constructors or
destructors.
An abstract class cannot support multiple
inheritance.
5
6. DECLARATION OF ABSTRACT CLASS
abstract class ab
{…
… }
An abstract class can contain either abstract
methods or non abstract methods.
Abstract members do not have any implementation
in the abstract class, but the same has to be
provided in its derived class.
6
7. WHAT AN INTERFACE IS?
In the real world, an interface means a medium to
interact with something.
To be precise, it's a point where two systems,
subjects, organizations and so on meet and
interact.
Similarly, in the programming world, an interface
means a contract to interact with multiple code
modules.
If a class wants to communicate with an interface, it
must implement it and define its members.
7
9. INTERFACE
Interfaces define properties, methods, and events,
which are the members of the interface.
Interfaces contain only the declaration of the
members.
It is the responsibility of the deriving class to define
the members.
It often helps in providing a standard structure that
the deriving classes would follow.
9
10. Cont..
An interface is a purely logical construct that describes
functionality without specifying implementation
An interface generally defines set of methods that will
be implemented by the class
But interface doesn’t implement any method itself
10
11. DECLARING INTERFACES
Interfaces are declared using the interface keyword.
It is similar to class declaration.
Interface statements are public by default.
Following is an example of an interface
declaration:
11
12. 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
13. 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
19. DIFFERENCES
Interface
Contains only signatures
Cannot contain
implementations
Cannot contain
constructor
A class can implement
multiple interface
Abstract class
Can contains signatures
Can contain
implementations
Can contain constructor
A class can implement
only one
abstract class
19