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)
Super class method
amarkirt saroay
Ranch Hand
Posts: 167
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
class SuperBase{ void print (SuperBase a){System.out.println("Super");}} class Base extends SuperBase{ void print(Base b){System.out.println("base");}} class Derived extends Base{ static void print (Derived d){System.out.println("Derived");}} in a test class: public static void main(String[] args) throws Exception { SuperBase a1=new SuperBase(); SuperBase b1=new Base(); Base c1=new Derived(); a1.print(new Base()); b1.print(new Derived()); c1.print(new Derived()); } }
How is the output as "SuperSuperBase" ? why second invocation calls Super method again?
[ July 24, 2008: Message edited by: amarkirt saroay ]
SCJP-75%
SCWCD-82%
Raphael Rabadan
Ranch Hand
Posts: 141
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Because it's and overloading, not an overriding...
The parameters of the methods are of diferent types. So, since its an overloading, its decided on compile time, not run time :-)
See these 2 classes:
class SuperBase { void print(SuperBase a) { System.out.println("Super"); } } class Base extends SuperBase { void print(Base b) { System.out.println("base"); } }
SCJP Java 6 (98%) -
Story
, SCJA (88%) -
Story
amarkirt saroay
Ranch Hand
Posts: 167
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks ! got it.
SCJP-75%
SCWCD-82%
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
overloaded method call rules
confused with Overloading rules
Which overloaded method?
(Solved!) Inheritance, polymorphism and overriding.
can any body explain me output of these program
More...