What Is Object-Oriented Programming How OO Model Applies To Programming Difference Between Classes and Objects. How To Create Classes and Object. How To Use Objects
What Is Object-Oriented Programming How OO Model Applies To Programming Difference Between Classes and Objects. How To Create Classes and Object. How To Use Objects
î
Objects
À
@ Object may contain other objects for example
motorcycle has engine,gearbox,brake and Lights. all
these are objects and motorcycle is bigger object.
@ Any object have function and data.
@ Engine contains following Function and Data.
agniting fuel Oil Temp
Moving piston Oil density
Opening valves RPM
Procedure
Ejecting burnt fuel Timing of fuel PROPERTaES
Rotating crank Types of fuel
3
Class
Objects
à
@ 3lass is a blueprint or Template that is used to create
and identify object.
@ 3lass is generic data.
@ Object is specific data.
getdate() dd,mm,yy
gettime() h,m,s
setdate()
settime()
@ Object d1 Object d2
13/12/2007 10/02/2009
12:25:30 11:10:15
sd() ,gd() sd(), gd()
×
@ an previous slide we have create DateTime class which
contain data like day,month,year and hour minutes second.
at also contain functions like getdate()and gettime() to
access data whereas setdate() and settime() allows to
manipulate the data.
@ We have object d1 with 13/12/2007 as specific date and
12:25:30 is a specific time and have setdate() and getdate()
similarly gettime() and settime() .
@ Similarly object d2 with specific date and specific time and
have setdate() and getdate() similarly gettime() and
settime() .
@ From same class we can create multiple objects.
6
@ Stack is used in recursion and evaluation of some
arithmetic expression.
@ Data structure is means of arranging the data in
memory.
@ Stack is one of data structures which LaFO list(Last in
first Out) list.
@ LaFO means whatever items are added last in the list
comes out first.
@ To keep track of last item in the list we have pointer
known as TOP.
@ Two operation can be perform on the list one is Push
which means insertion and another is Pop which
means deletion. af stack is implemented by array the
TOP pointer with no element will have value -1. stack
can also be implemented by linked list
@ Diagrammatic explanation of PUSH operation of stack
Top 20
10 10
TOP
EMPTY TOP PUSH 10
PUSH 20
x
TOP
Pop Pop 20
m
m
m
m
Object s1 Object s2
5 elements 7 elements
Top=4 Top=6
push(),pop() push(), pop()
class Sample
{
public int i;
public float j;
}
public class 3lassDemo
{
public static void Main()
{
Sample a,b;
a=new Sample();
a.i=10; a.j=3.14f;
3onsole.WriteLine(a.i + Dz Dz+a.j);
b=new Sample();
b.i=20;b=.j=6.28f;
3onsole.WriteLine(bi + Dz Dz+b.j);
3onsole.ReadLine();
}
}
©
@ class 3lassDemo contain Main(). Within Main(),we
say Sample a,b. Sample is a class which is user-Defined
.so we define class Sample which contains public int a
and public float j.
@ These program have two classes ,Sample and
3lassDemo. a and b are reference to object of type
sample. Reference hold the address of the objects.
@ To create object we use keyword
@ For example a=new Sample();
@ a is holding the address of nameless object that has
been created.
@ a.i=10 and a.j=3.14f means a and j belonging to object
to which a is pointing. Similar for b =new Sample(),we
say b.i=20 and b.j=6.28f and finally print those values.
î6
class Sample
{
public int i;
public float j;
public void SetData(int ii, float jj)
{
i=ii;
j=jj;
}
public void ShowData()
{
3onsole.WriteLine( i + Dzdz Dzdz+j);
}
î6
public class 3lassDemo
{
public static void Main()
{
Sample a,b;
a=new Sample();
a.SetData(10,3.14f);
a.ShowData();
b=new Sample();
b.SetData(20,6.28f);
b.ShowData();
3onsole.ReadLine();
}
}
î6
@ an previous program
6
@ //Program 1
using System;
class Sample
{
public int age;
}
class Demo
{
public static void Main()
{
sample s1,s2; int x;
s1=new Sample();
if(x>0)
s1.age=x;
s2=new Sample();
if(x>0)
s2.age=x;
}
}
@ //Program 2
using System;
class Sample
{
public int age;
public void SetData(int i)
{
if(x>0)
age=x;
}
}
class Demo
{
public static void Main()
{
sample s1,s2; int x;
s1=new Sample();
s1.SetData(x);
s2=new Sample();
s2.SetData(x);
}
}