Object As An Argument - Java

WRITE A PROGRAM TO PASS THE OBJECTS AS AN ARGUMENTS.

class Demo
{
int a,b;
public void get(Demo D)
{
a=D.a;
b=D.b;
}
public void put()
{
System.out.println(a+b);
}
}
class A8
{
public static void main(String args[])
{
Demo d=new Demo();
Demo c=new Demo();
d.a=10;
d.b=20;
c.get(d);
c.put();
}
}

WRITE A PROGRAM TO FIND THE BIG NUMBER OUT OF TWO NUMBERS USING ARGUMENTS PASSING AND OBJECTS PASSING.

class Test
{
int a;
public void get(int x)
{
a=x;
}
public int put(Test t1,Test t2)
{
if(t1.a>t2.a)
{
return(t1.a);
}
else
{
return(t2.a);
}
}
}
class Sample
{
public static void main(String args[])
{
 Test t1=new Test();
Test t2=new Test();
Test t=new Test();
t1.get(10);
t2.get(20);
int y=t.put(t1,t2);
System.out.println(y);
}
}

WRITE A PROGRAM ON REFERENCING OBJECTS.

class Demo
{
int x,y;
public void get(int a,int b)
{
x=a;
y=b;
}
public void get(Demo D)
{
D.x=D.x+10;
D.y=D.y+10;
}
}
class Sum
{
public static void main(String args[])
{
Demo D=new Demo();
D.get(10,20);
D.get(D);
System.out.println(D.x+D.y);
}
}

WRITE A PROGRAM ON RETURNING OBJECTS.

class Demo
{
int a,b,c;
public void get(int x,int y)
{
a=x;
b=y;
}
public Demo Set(Demo D,Demo c)
{
Demo k=new Demo();
k.a=D.a+c.a;
k.b=D.b+c.b;
k.c=k.a+k.b;
return(k);
}
public void put()
{
System.out.println("Sum: "+c);
}
}
class Sample
{
public static void main(String args[])
{
Demo p=new Demo();
Demo q=new Demo();
Demo r=new Demo();
p.get(10,20);
q.get(30,40);
r=r.Set(p,q);
r.put();
}
}

WRITE A PROGRAM TO ADD THE TWO TIMINGS BY PASSING ARGUMENTS AND RETURN OBJECT.

class Demo
{
int a,b,c;
public void get(int x,int y)
{
a=x;
b=y;
}
public Demo set(Demo D,Demo C)
{
Demo k=new Demo();
k.a=D.a+C.a;
k.b=D.b+C.b;
if(k.b>60)
{
k.a=k.a+1;
k.b=k.b%60;
}
return(k);
}
public void put()
{
System.out.println("Time: "+a+" "+
}
}
class Sample
{
public static void main(String args[])
{
Demo p=new Demo();
Demo q=new Demo();
Demo r=new Demo();
p.get(5,30);
q.get(6,40);
r=r.set(p,q);
r.put();
}
}

WRITE A PROGRAM TO FIND THE GRAND TOTAL MARKS OF TWO STUDENTS PASSING OBJECTS AS AN ARGUMENTS.

class Abc
{
int a,b,c;
public void get(int x,int y,int z)
{
a=x;
b=y;
c=z;
}
public void put()
{
System.out.println("Total: "+(a+b+c));
System.out.println("Average: "+(a+b+c)/3);
}
public void print(Abc x,Abc y)
{
System.out.println("Tot: "+(x.a+x.b+x.c+y.a+y.b+y.c));
System.out.println("Avg: "+(x.a+x.b+x.c+y.a+y.b+y.c)/6);
}
}
class Sample
{
public static void main(String args[])
{
Abc x,y,z;
x=new Abc();
y=new Abc();
z=new Abc();
x.get(50,50,50);
y.get(40,30,20);
z.print(x,y);
x.put();
y.put();
}
}

 

For
More Explanation
&
Online Classes

Contact Us:
+919885348743