Object-Oriented Programming 1
Object-Oriented Programming 1
programming
FAHAD HUSSAIN
MCS, MSCS, DAE(CIT)
The main aim of OOP is to bind together the data and the functions that operate
on them so that no other part of the code can access this data except that
function.
1)Encapsulation:
2)Inheritance:
3)Polymorphism:
4)Abstraction:
5)*Exception Handling
1. What is class
2. What is object
3. What is namespaces
4. What is function/Method
5. What is Constructor and its types
6. What is Destructors
Object:
An Object is an identifiable entity with some characteristics and behavior. An Object is an
instance of a Class. When a class is defined, no memory is allocated but when it is
instantiated (i.e. an object is created) memory is allocated.
Namespaces
Namespaces in C# are used to organize too many classes so that it can be easy to handle the
application. We use System.Console where System is the namespace and Console is the
class. To access the class of a namespace, we need to use namespacename.classname. We
can use using keyword so that we don't have to use complete name all the time.
Types of Constructor
• Default Constructor
• Parametrized Constructor (with overload concept)
• Copy Constructor
• Private Constructor
• Static Constructor
Copy Constructor
This constructor will creates an object by copying
variables from another object. Its main use is to
initialize a new instance to the values of an existing
instance.
Points To Remember :
It can’t be called directly.
When it is executing then the user has no control.
It does not take access modifiers or any parameters.
It is called automatically to initialize the class before the first instance created.
• Constructor of a class must have the same name as the class name in
which it resides.
• A constructor can not be abstract, final, and Synchronized.
• Within a class, you can create only one static constructor.
• A constructor doesn’t have any return type, not even void.
• A static constructor cannot be a parameterized constructor.
• A class can have any number of constructors.
• Access modifiers can be used in constructor declaration to control its
access i.e. which other class can call the constructor.
• In c#, destructors can be used only in classes and a class can contain only one destructor.
• The destructor in class can be represented by using tilde (~) operator
• The destructor in c# won’t accept any parameters and access modifiers.
• The destructor will invoke automatically, whenever an instance of class is no longer needed.
• The destructor automatically invoked by garbage collector whenever the class objects that
are no longer needed in application.
1)Encapsulation:
2)Inheritance:
3)Polymorphism:
4)Abstraction:
5)*Exception Handling
1. Public
2. Private
3. Protected
4. Internal
5. Protected Internal
6. Private Protected
Using Private access modifier, we can Encapsulation the Code (Class, Method etc)…