Login    New User    Forgot Password    Help      

Object as parameter (Constructor)

Java Tutorials

 

Example

class abc
{
int a;
int b;
        void getdata(abc ob)
        {
        a=ob.a;
        b=ob.b;
        }

        void showdata()
        {
        System.out.println("Value of a is " +a);
        System.out.println("Value of b is "+b);
        }
}
class clas7
{
public static void main(String args[])
{
abc ob1=new abc();
abc ob2=new abc();
ob1.a=10;
ob1.b=20;
ob2.getdata(ob1);
ob2.showdata();
}
}

Output

e:\java\java clas7

Value of a is 10

Value of b is 20

Java Tutorials