File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Problem regarding oops concept Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem regarding oops concept" Watch "Problem regarding oops concept" New topic
Author

Problem regarding oops concept

sandeep patrudu
Greenhorn

Joined: Feb 22, 2007
Posts: 6
Hi everyone,
I cannot figure it out why it is printing "Sub" in the Output even we are a passing a "null" parameter to foo()method in the below given code:

class Super{}


class Sub extends Super{

}


public class Test{



public void foo(Sub sub){
System.out.println("Sub");
}

public void foo(Super sup)
{
System.out.println("Super");
}

public static void main(String args[]){

new Test().foo(null);
}
}
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

See What is a most-specific method? from our SCJP FAQ (and note the last line of that answer).


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
sandeep patrudu
Greenhorn

Joined: Feb 22, 2007
Posts: 6
Hi Marc,
Thanks Marc for your reply.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem regarding oops concept
 
Similar Threads
Overloading
overridden method output
Method Invocation
A constructor question
Can final method be overridden?