Object Oriented Programming Experiments Practical
Object Oriented Programming Experiments Practical
RAMGARH, JHARKHAND
RAMG AR A N D
HARKHA
PRACTICAL
S. NO.
NO. OF EXPERIMENTS PAGE NO.
weide a ova aungam to ind the bibonai ol o2.
Ol Sens usihg Hecursive aud nen
reurstVe
Punc4bn
Wuke a Souwa psogram to mulhph two
02 Jiveu mam'eus 05 0Y
SUBMITTED BY:
HARSH SINHA
SUBJECT: oblutOneniecd
uogrammi'ng(0ops)
COURSE:-..2k.A....SE.
2021-2025
SESSION:-...
SIGNATURE:.
Date
Page O
Expeimend
Aim Hsuite a Jaula ungamdokind he Eibonae-
Seuies using ueirsite_and _non_ILNSLVE
Lunchhs
escipba
PhanasaAelis A Libonatei Senks h -
Jasla is a Sequence o numbets Such hat e y hid-
nunher_ 14 epu/ ko he iun s h e pyezibus turo
numbers
fote o,,1,2,3,5,213, 2,34,
class fib
int a,b.c;
void nonrecursiveint n) //Non recursive function to find the Fibonacci series.
a=0;
b=1
System.out.print(a+ " +b);
c=atb;
while(c=n)
System.out.prin(c);
a=b;
b-c
catb;
if(n=0)
return (0);
if(n=1)
return (1);
else
return(recursive(n-1)+recursive(n-2));
int n=5;
System.out.println("The Fibonacci series using non recursive is");
/Creating object for the fib class.
fib f-new fib)%
I/ Calling non recursive function oF fib class.
f.nonrecursive(n);
System.out.println("in The Fibonacci series using recursive is");
for(int i=0;i<=n;it+)
/ Calling recursive function of fib class.
int Fl=f.recursive(i);
System.out.print(F1);
Expeinteod
Ain Huite a Jala Puagtam to muldiply -tuoogiven
Matnces
Daphiao
Matn't mulhphhadhn, ako_Atacon
AAatdces
as Mabnr punduce 2nd he_multplhkabhn # two
Mabples pueduresa ingle _2tn
for(int j=0:j<3;j++)
cfi]l-0;
for(int k=0;k<3;k++)
clilb+ali][K)*b[k]6):
l/end of k loop
//printing matrix element
System.out.print(c[i]G]+" ");
Wend of j loop
System.out.println(); /new line
Date
Pege O4
Expedimend3
Ain Kuite_a Jauta uegthm_bar rlhnd_aveushadng
and Contuster_Ahadings
ovenloadatng
Mhod 2 4 a bnrep
ak Janin uhich_ure can ueatemulbpde mehed
he 4he_So2e ame inhe am2_Llas,And alMtthoda
holks in Kuett aays
he ase ef Mote han one sheuth in2y
lnshmeLlas
Rgron
Mthododnlaodke
import java.io.*;
class MethodOverloadingEx {
return a + b;
return a +b+c;
Lonstuntor ave/oihna
-
public class Student{
instance variables of the class
int id;
String name,
Student(){
System.out.println("this a default constructor");
Student(int i, String n){
id = i;
name=n,
EEkalpana>javac Student.java
E:kalpana>java Student
his a default construc tor
values :
Default Cons tructor
Student Id :
Student Nane : rnull
Construct0r values 3
Paraneterized
Student 1d : 10
Student Nane Kalpana
Date.
Page D7
Epelinent4
An uite a Jah uogtomh dplay he
tmplnyee deeuls _usi
import java.util.*;
class EmployeeDetails
float s=sc.nextFloat(O;
System.out.println("name is"+n+"idis"+i+"ageis"+a"'salaryis"+s);
123456789
nane is: _Socse
id is 3
age is : 2
salary is:1.23456792E8
Date
Fage 0
EpetiaentL
Ain hlutte a aun ugnm-that heeks_alhethed a a
E:kalpana>