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
Help coderanch get a
new server
by contributing to the
fundraiser
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
Ron McLeod
Paul Clapham
Devaka Cooray
Liutauras Vilda
Sheriffs:
Jeanne Boyarsky
paul wheaton
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Tim Moores
Carey Brown
Mikalai Zaikin
Bartenders:
Lou Hamers
Piet Souris
Frits Walraven
Forum:
Programmer Certification (OCPJP)
Why the output of this program is "parent"?
Aakash Chandel
Greenhorn
Posts: 27
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
class Parent { String message = "parent"; } class Child extends Parent { String message = "child"; } public class Test { public static void main(String[] args) { Parent yo = new Child(); System.out.println(yo.message); } }
Why the output of this program is "parent"? Shouldn't
polymorphism
apply and the output come as "child"?
Please guide.
Astha Sharma
Ranch Hand
Posts: 250
I like...
posted 12 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
It depends upon reference only that instance variable of which type will be accessed. Polymorphism doesn't work here. It works only on instance methods.
Astha - OCPJP 6 (90%)
naveen yadav
Ranch Hand
Posts: 384
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Same behavior is also true for
1. hidden fields and methods
2. overloaded methods
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Thangaraj S.
Please explain the initialization sequence in this code
doubt in overloading
Problem -- Virtual Method Invocation
what is the reason behind this
More...