This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Output of the program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Output of the program" Watch "Output of the program" New topic

Output of the program

Phillipe Rodrigues
Ranch Hand

Joined: Oct 30, 2007
Posts: 165
What is the output for the comments(1),(2)?Why?

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2904

For comment 1 , this link may help ,

look this example

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

Hope this help

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 378
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.
Have you checked out Aspose?
subject: Output of the program
It's not a secret anymore!