5. Object Oriented Programming (OOP)
5. Object Oriented Programming (OOP)
class Car
{
string color = "red";
}
Objects
Example
class Geeks{
// constructor of Geeks class
public Geeks( ) { }
}
1. Default Constructor
2. Parameterized Constructor
3. Copy Constructor
Default Constructor
A constructor with no parameters is called a Default
constructor.
Syntax
Parameterized
Constructor
A constructor having at least one parameter is called a
parameterized constructor. It can initialize each instance of the
class to different values.
it accepts one or more arguments or parameters, to initialize an
object with specific values, when created.
Syntax
Copy Constructor
Copy Constructor
A copy constructor is used to create a new object by copying the
values from an existing object of the same class.
The copy constructor is a constructor that creates an object by
initializing it with an object of the same class which has been
created previously.
Syntax
Polymorphism
Method overriding says the child class has the same method as
declared in the parent class. It means if the child class provides the
specific implementation of the method that has been provided by one of
its parent classes then it is known as method overriding.
Encapsulation
What Is an Exception?
An exception is a problem that arises during the
execution of a program. A C# exception is a
response to an exceptional circumstance that
arises while a program is running, such as an
attempt to divide by zero.
C# exception handling is built upon four
keywords: try, catch, finally, and throw.
try, catch, finally, and throw