• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
Bartenders:
  • Himai Minh
  • Carey Brown
  • Frits Walraven

what is the ouptut and how..

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
11. try {
12. if ((new Object))(.equals((new Object()))) {
13. System.out.println(�equal�);
14. )else{
15. System.out.println(�not equal�);
16. }
17. }catch (Exception e) {
18. System.out.println(�exception�);
19. }
What is the result?

A. equal
B. not equal
C. exception
D. Compilation fails.
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you run the program you will see you get a compilation errors. There are mistakes in the type of braces in else block, and also in the new Object.

Ofcourse if you fix these, the out put will be as expected "not equal"
 
Supriya Nimakuri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry ...i didnt check the syntax
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why this is "not equal", still we are comparing same object and equal is not "==" , which compares object reference. I think it should "equal" but its not
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vasukola vasukola:
Why this is "not equal", still we are comparing same object and equal is not "==" , which compares object reference. I think it should "equal" but its not



Hi guys,
if we have a look at equals() in the Object class we see:


that's why it prints "not equal"

Finner
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic