Why and How answer is not same? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why and How answer is not same?

public class Program { public static void main(String[] args) { int arr1[]={1,2,3}; int arr2[]={1,2,3}; if(arr1==arr2) System.out.println("same"); else System.out.println("not same"); Answer :not same

25th Jan 2020, 2:59 AM
Ajul Kushwah
Ajul Kushwah - avatar
3 Answers
+ 4
Why do you think it should be same? Just because it has similar elements? Consider this, there is family1 with three members and then there is family2 with another 3 members. Though they are 2 families having same number of people but aren't they actually different? Don't they have different addresses? So apply the same to arrays is java which are nothing but objects which are obviously created in different memory locations.
25th Jan 2020, 3:29 AM
Avinesh
Avinesh - avatar
+ 3
Arr1&arr2 Different Refrences Variable point to Two different object
25th Jan 2020, 3:08 AM
Mø Fathi
Mø Fathi - avatar
+ 2
Please use other tags than a! you have a java question so tag java would be a good idea.
25th Jan 2020, 6:07 AM
Oma Falk
Oma Falk - avatar