Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

2.
Abstract Class
Motivation: if you think no object of a class should be
created, declare the class abstract
In general, an abstract class is a placeholder in a class
hierarchy that represents a generic concept
The use of abstract classes is a design decision; it helps us
establish common elements in a class that is too general to
instantiate
Vehicle
Car
Boat
Plane
2

4.
Abstract Class: Some Properties
An abstract class cannot be instantiated
but you can define a reference of an abstract class
Only abstract classes can contain abstract
methods
The child of an abstract class must override
the abstract methods of the parent, or it too
must be declared abstract
4

5.
C# Contains Many Other Features to
Further Refine the Definition of a Class
Sealed class or method
if you declare a class or method sealed, then the
class or method cannot be extended
Operator overloading
you can define operators for a class so that
operations look more like a normal arithmetic
operation
5

6.
Using Interface for Multiple Inheritance
Java/C# decision: single inheritance,
meaning that a derived class can have only
one parent class
To take the advantages of multiple
inheritance, Java/C# defines interfaces,
which give us the best aspects of multiple
inheritance without the complexity
6

7.
C# Interface
A C# interface is a collection of methods, and properties
it can actually include other types of definitions
These methods and properties have no implementation
An interface is used to formally define a set of methods that a
class will implement
An interface captures one aspect of a class
If class D is derived from class B, then you should feel comfortable in
saying an object of D is also a B
If class D implements interface I, then you should feel comfortable in
saying an object of D has I perspective
7

9.
Interfaces
Methods in an interface have public visibility by default
An interface cannot be instantiated
A class implements an interface by
stating so in the class header after :
A class can implement multiple interfaces: the interfaces
are separated by commas
If a class asserts that it implements an interface, it must
define all methods in the interface or the compiler will
produce errors
A class that implements an interface can implement
other methods as well
9

10.
Polymorphism via Interfaces
An interface name can be used as the type of
an object reference variable
IDoable obj;
The obj reference can be used to point to
any object of any class that implements the
IDoable interface
The version of doThis that the following line
invokes depends on the type of object that
obj is referring to:
obj.doThis();
10

12.
Exception Handing
Exception handling is an in built mechanism
in .NET framework to detect and handle run
time errors.
The .NET framework contains lots of standard
exceptions.
The exceptions are anomalies that occur
during the execution of a program.
They can be because of user, logic or system
errors.
12

13.
Exception Handing
If a user (programmer) do not provide a
mechanism to handle these anomalies, the
.NET run time environment provide a default
mechanism, which terminates the program
execution.
13