Your answer is only valid for String objects and because String overrides equals to return true if the "represents the same sequence of characters". The equals method compares the objects. AADProgramming 5, 11 11 gold badges 34 34 silver badges 57 57 bronze badges.
Andrew Carr Andrew Carr 6 6 silver badges 16 16 bronze badges. Shanu Gupta 3, 2 2 gold badges 16 16 silver badges 28 28 bronze badges. Simple and easiest answer — gulab patel. Sarat Chandra Sarat Chandra 4, 24 24 silver badges 27 27 bronze badges. Simple and best explanation — Sritam Jagadev. They are aliases; System. Tadele Ayelegn Tadele Ayelegn 3, 1 1 gold badge 29 29 silver badges 27 27 bronze badges.
For example : System. Miriam Farber Ravi Patel Ravi Patel 1 1 silver badge 3 3 bronze badges. But in case of equals method it's depends's on implementation if we are overridden equals method than it compares object on basic of implementation given in overridden method.
Sachin Jadhav Sachin Jadhav 1 1 silver badge 6 6 bronze badges. Dearwolves Dearwolves 4 4 silver badges 16 16 bronze badges. Elroch Elroch 1 1 silver badge 7 7 bronze badges. Wrapper objects for primitive types - i. It purely depends on Wrapper's cache. Below code will print false because default cache is limited to to Mike Clark Mike Clark 1, 10 10 silver badges 21 21 bronze badges.
In short, the answer is "Yes". Pang 8, gold badges 82 82 silver badges bronze badges. JamesOstmann JamesOstmann 41 4 4 bronze badges. It means: object1. It is the difference between identity and equivalence. Steve White Steve White 3 3 silver badges 9 9 bronze badges.
Ousama Ousama 2 2 gold badges 10 10 silver badges 17 17 bronze badges. The Overflow Blog. Does ES6 make JavaScript frameworks obsolete? Podcast Do polyglots have an edge when it comes to mastering programming Featured on Meta.
Now live: A fully responsive profile. Linked See more linked questions. Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled. Thanks for reading this article so far. If you like this core Java interview question and my explanation then please share it with your friends and colleagues. If you have any doubt or feedback then please drop a note. Labels: core java , core java interview question answer , String.
Anonymous January 7, at AM. Unknown February 21, at AM. Anonymous October 6, at PM. Anonymous November 7, at AM. Top 5 Courses to learn Unreal Engine in - Bes How to add, subtract days, months, years, hours fr What is final in Java? Final variable , Method and What is Type Casting in Java?
Casting one Class to How to use Lombok Library in Java? Observer design Pattern in Java with Real world co How to get current date, month, year and day of we How to convert milliseconds to Date in Java - Tuto How to check if a number is a palindrome or not in How to check if String contains another SubString Difference between mvn install, release and deploy How to check if a String is numeric in Java?
Use i How to remove duplicates elements from ArrayList i How to read input from command line in Java using Top 3 Free and Best Svelte. What is Constructor in Java with Example — Constru How to sort HashMap by key and value in Java - Has How to comment uncomment single line and block of Top 10 Coursera Certifications, Courses, and Speci A string with no numeric value is converts to NaN Not a Number , which returns false.
This operator performs type casting for equality. The first operand should be a variable. It checks whether its two operands are the same or not by changing expression from one data type to others.
Therefore, the output is 7. In the below program, the value of variable x is
0コメント