Wednesday, 7 October 2015

Java Program - Passing Objects to the methords

import java.io.*;
import java.util.*;
import java.lang.*;
class Acceptt{
public static void main(String args[]) throws IOException{
First obj1 = new First(10);
First obj2 = new First(20);
Second obj3 = new Second();
System.out.println("The HashCode value of Obj1 is " +obj1.hashCode());
System.out.println("The HashCode Value of Obj2 is " +obj2.hashCode());
System.out.println("The value of obj1 is " +obj1.i);
System.out.println("The value of obj2 is " +obj2.i);
obj3.check(obj1, obj2);
System.out.println("In the main Function");
System.out.println("The HashCode value of Obj1 is " +obj1.hashCode());
System.out.println("The HashCode Value of Obj2 is " +obj2.hashCode());
System.out.println("The value of obj1 is " +obj1.i);
System.out.println("The value of obj2 is " +obj2.i);

}
}

class First{

int i;

First(int j){

this.i=j;
}
}

class Second{
void check(First k,First d){
int temp;
temp=k.i;
k.i=d.i;
d.i=temp;
System.out.println("In the sub Function");
System.out.println("The HashCode value of Obj1 is " +k.hashCode());
System.out.println("The HashCode Value of Obj2 is " +d.hashCode());
System.out.println("In the sub Function");

System.out.println("The value of obj1 is " +k.i);
System.out.println("The value of obj2 is " +d.i);
}

}


Output :-
The HashCode value of Obj1 is 366712642
The HashCode Value of Obj2 is 1829164700
The value of obj1 is 10
The value of obj2 is 20
In the sub Function
The HashCode value of Obj1 is 366712642
The HashCode Value of Obj2 is 1829164700
In the sub Function
The value of obj1 is 20
The value of obj2 is 10
In the main Function
The HashCode value of Obj1 is 366712642
The HashCode Value of Obj2 is 1829164700
The value of obj1 is 20
The value of obj2 is 10

No comments:

Post a Comment