Object Oriented Application
Object Oriented Application
OBJECT: An Object is an Entity that has Properties for identifying its State and for Validation,
Method for Behavior/Functionality and
Object Oriented Application: It’s a collection of related objects, communicating with each other,
exchanging messages with other in a controlled environment as per the rules of the business.
1) Encapsulation
2) Inheritance
3) Polymorphism
Inheritance: The process of acquiring the existing functionality of the parent and
with new added features and functionality by a child object is called Inheritance.
Using Inheritance redundant programs, programming codes can be
eliminated and the use of previously defined classes may be continued.
Inheritance decreases coding part of the programmer.
The advantages of Inheritance are Generalization, Extensibility and
reusability.
POLYMORPHISM:
Console.WriteLine(C);
long verylong = 99999;
Console.WriteLine(verylong);
string st = "Anoj";Console.WriteLine(st);
Console.WriteLine("The st value is");
Write(); WriteLine():
Write() prints text without a new line. WriteLine() moves to the next line
after Printing
Console.WriteLine("Hello, World!");
int a = 30;
int b = 20;
int result = 0;
result = a + b;
Console.WriteLine(result);
result = a - b;
Console.WriteLine(result);
result = a/b;
Console.WriteLine(result);
result = a * b;
Console.WriteLine(result);
result = a % b;
Console.WriteLine(result);
Console.ReadKey();
string name = "prashanth";
string hisname = a+ name;
Console.WriteLine(hisname);
Decimal x = 1.2M;
Console.WriteLine(x);
namespace HelloWorld
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}
MYLIBPRACTICE:
SOLUTION EXPLORER
CONTEXT
ADD
NEW
NEW PROJECT
THERE IN SOLUTION EXPLORER WE WILL SEE CLASS.1 and namespace visual window
8) HERE YOU WILL SEE PROGRAMM .C WINDOW WERE YOU WILL UPDATE LIBRARIES
BY SAY USING
Class.cs
namespace MYPROJECT4
{
public class Class1
{
public long a = 10000;
public long b = 11000;
}
}
Program.cs
Using Myproject1:
using MYPROJECT4;
Class1 objclass1 = new Class1();
Console.WriteLine(objclass1.a);
Console.WriteLine(objclass1.b);
}
//methods
public void Add()
{
int d = 10;
int e = 20;
int result = 0;
result= d+ e;
Console.WriteLine(result);
}
}
Parametrised method()
int result = 0;
result = a + b;
Console.WriteLine(result);,
using PARAMMETHODLIBRARY;
Class1 objclass1 = new Class1();
objclass1.RaviAdd(10, 20);
namespace METHODWITH_WRITTEN
{
public class Class1
{
public int a = 1000;
public int b = 2000;
public Class1()
{
a = 300;
b = 200;
}
public void Subtract()
{
int d = 20;
int e = 10;
int result = 0;
result = d - e;
Console.WriteLine(result);
}
public void RaviSubtract(int a, int b)
{
int result = 0;
result = a - b;
Console.WriteLine(result);
}
public int Subtractwritten()
{
int d = 20;
int e = 10;
int result = 0;
result = d - e;
return result;
}
public int Subtractwtparartn(int d,int e)
{
int result = 0;
result = d - e;
return result;
}
}
using METHODWITH_WRITTEN;
Class1 objclass1 = new Class1();
int result = 0;
// calling methods
result = objclass1.Subtractwritten();
Console.WriteLine(result);
int result1 = 0;
result1 = objclass1.Subtractwtparartn(10,5);
Console.WriteLine(result1);
}
}
}
## child class
namespace InheretenceLibrary
{
public class Child : Parent
{
}
}
## objclass:
using InheretenceLibrary;
Child objchild = new Child();
objchild.GetFee();
Child.cs
namespace INHERITENCELIBRARYM
{
public class Child : Parent, Interface1
{
public void Add()
{
throw new NotImplementedException();
}
}
}
namespace InheritenceLibraryMultiple
{
public class Parent
{
public virtual void AllEmployeesSalary()
{
}
Abstract Class: Initially it is a Base Class because,
We cannot create an object for Abstract class. But Abstract class
is accessed through inheritance.
A method without any method body is known as an Abstract
method.
Abstract class contain:1) Abstract methods
2) Non Abstract methods
-In abstract class Override is mandatory, whereas in method
Overriding it is an optional
namespace ADOCUSTOMERLIB
{
public class Employees
{
public void ConnectEmployees()
{
string strConnectionstring = "Data Source=DESKTOP-383K38T;Initial
Catalog=Office;Integrated Security=True;Trust Server Certificate=True";
SqlConnection objSqlConnection = new SqlConnection();
objSqlConnection.ConnectionString = strConnectionstring;
objSqlConnection.Open();
Console.WriteLine("you connect db");
if (dataReader.HasRows)
{
Console.WriteLine("EmployeID || lastName || FirstName || BirthDate || Photo ||
Notes ");
while (dataReader.Read())
{
Console.WriteLine("{0} || {1} || {2} || {3} || {4} || {5}
||", dataReader[0], dataReader[1], dataReader[2], dataReader[3], dataReader[4],
dataReader[5]);
}
}
}
}
}
With PARAMETERS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Data.SqlClient;
namespace WithParamLIB
{
public class EmployeesWithParam
{
public void GetEmployees(int EmployeesId)
{
string strConnectionstring = "Data Source=DESKTOP-383K38T;Initial
Catalog=Office;Integrated Security=True;Trust Server Certificate=True";
SqlConnection objSqlConnection = new SqlConnection();
objSqlConnection.ConnectionString = strConnectionstring;
objSqlConnection.Open();
Console.WriteLine("you connect db");
if (dataReader.HasRows)
{
Console.WriteLine("EmployeID || lastName || FirstName || BirthDate || Photo ||
Notes ");
while (dataReader.Read())
{
Console.WriteLine("{0} || {1} || {2} || {3} || {4} || {5}
||", dataReader[0], dataReader[1], dataReader[2], dataReader[3], dataReader[4], dataReader[5]);
}
}
}
}