Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem regarding oops concept

 
sandeep patrudu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See What is a most-specific method? from our SCJP FAQ (and note the last line of that answer).
 
sandeep patrudu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marc,
Thanks Marc for your reply.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic