The first way to achieve this is by using the constructor. The example has given below
public class integer {
private int a;
private int b;
integer() {
}
integer(int a, int b) {
this.a = a;
this.b = b;
}
integer sum(int c, int d) {
integer result = new integer(c, d);
return result;
}
public static void main(String[] args) {
integer i = new integer();
integer n = i.sum(10, 12);
System.out.println(n.a);
System.out.println(n.b);
}
}
public class integer {
int[] sum(int c, int d) {
int arr[] = new int[2];
arr[0]=c;
arr[1]=d;
return arr;
}
public static void main(String[] args) {
integer i =new integer();
int[] n = i.sum(70, 50);
System.out.println(n[0]);
System.out.println(n[1]);
}
}
0 Comments