Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
Qn on function call ().
cs singh
Ranch Hand
Posts: 36
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Consider the following code . what is the result of compiling & executing C.java ? class A { } class B extends A { } class C extends B { static void doSomething ( A x , A y ) {System.out.print("AA");} static void doSomething ( A x , B y ) {System.out.print("AB");} static void doSomething ( B x , A y ) {System.out.print("BA");} static void doSomething ( B x , B y ) {System.out.print("BB");} static void doSomething ( C x , C y ) { System.out.println("CC");} public static void main(String[] args) { doSomething(null,null); } } Options : a . Prints AA to the console b . Prints AB to the console c . Prints BA to the console d . Prints BB to the console e . Prints CC to the console
why is the answer e??
gaurav singhal
Ranch Hand
Posts: 135
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
In such a scenario always the compiler look for most specific class and C is most specific class in this scenario.
For more clarification refer to the following post.
https://coderanch.com/t/252997/java-programmer-SCJP/certification/Passing-null-references
it's a teeny, tiny, wafer thin ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
overriding question
what is the result of compiling & executing. doSomething(null,null);
Passing Null which mehod is called?
Doubt regarding overloading
about overloading
More...