Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Output of the program

 
Phillipe Rodrigues
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the output for the comments(1),(2)?Why?


 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For comment 1 , this link may help ,

look this example


and for 2 comment , the equals checks for contents equality !

Hope this help
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are only able to access members of the declared type. In this case Object. When these members are invoked the implementation of the actual object is invoked.

Object has getClass method and the String implementation does not override it so the Object class's getClass method will be called.

Object has equals method but String class overrides the equals method so the string class's equals method is called.

String has length() method but Object does not have it so if you try to invoke the length() method on an reference of type Object compiler will complain.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic