Classes and Objects
Classes and Objects
Class Definihond
d olus olafnithon starts wih the kyword
interfaca, followed tby the intuface (clasa) nouna
na
The clau body is en closed by a pair of urly
braces.
example
intuface Box: NSs Object
Tnstonce variables
doubje
double length; ung th of box
bread th ; Bread th of box
propurty
proputy (nonatomic, readwrite ) dlouble hight
end
e Kample ’
Box boxd = [C Borallag init];erate boxs object of
the type Box
Box box 2 =[[ Box alloc] init]; lerate box2 object of
the type Box
Cxample
import
<Foundation /Foun dation.h)
intefae Box: NSObjeck
double lengthj
olovble breadl th
dou ble heightj
atormic radwrite ) double hight ;
propurty
(double) volu
end
int main
Function ’
Method Declaration ’
Syratax
-(retorn-type) fonchon _na (argumunt Typ)
arguement Namei joining Argumant l(arguemnt Typ2)
arguement Nama2 joining Arguemnt N: (argunant TypeN)
arguemut NameN;
Method Defnihon
Syntax
example program
end
implemantation Sample
Cla
Zmehad dafnition
-(int)max: (int) numi and Num2int) nwm2
int result
if (num1 > num2)
result = num 1;
else
ruult = wml
hetum rsult
end
int main )
intaz l00
int b= 200;
int net
Sample Clas
net =
Samples ll SampleClau alloc]init
Lsarmple.
NSLoq Q"Max
max : a
val is :
and Numl ib]
%d n" ret);
return 0,
Poge
Log Handlinq
NSLoq metho d isis Used to print logs.
Sy ntax NSLog (Q"hulo );