GeeCON Prague 2014*
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


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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem regarding oops concept