This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes String Vs Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String Vs Object" Watch "String Vs Object" New topic

String Vs Object

Pandurangan Rakesh

Joined: Jun 06, 2004
Posts: 24

I have the following program

Now when i compile and run the program alweays the method show() with String parameter is called i.e the output is always String null and never Object null.Can u tell me why?
[ June 06, 2004: Message edited by: Carl Trusiak ]
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 29287

Since String is a subclass of Object, it gets called. Java calls the method with the most specific parameter.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
I'm moving this to Beginner
I agree. Here's the link:
subject: String Vs Object
Similar Threads
(MyClass) null
What's in new String() object?
mock exam question
Overloading Example doubt
Overloading question...