Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
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:
Beginning Java
Inheritance
archu sweet
Ranch Hand
Posts: 66
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
class ClassA {} class ClassB extends ClassA {} class ClassC extends ClassA {} and: ClassA p0 = new ClassA(); ClassB p1 = new ClassB();
I want to know how come p0=p1 is true ??
Jesper de Jong
Java Cowboy
Posts: 16084
88
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I guess you mean p0 == p1, because p0 = p1 is not a boolean expression.
Why do you think it is true? Did you try this code out?
Jesper's Blog
-
Pluralsight Author Page
archu sweet
Ranch Hand
Posts: 66
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
yes i meant p0 == p1...i tried out it says it is valid....but they belong to different classes how can they be equal ??
Matthew Brown
Bartender
Posts: 4568
9
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It's valid to compare them, because a ClassB IS-A ClassA. Which means that it's possible for ClassA and ClassB references to be equal. For example:
ClassB p0 = new ClassB(); ClassA p1 = p0; // OK because ClassB extends ClassA
Then
p0 == p1
is true.
The compiler will only stop you comparing them if they can't possibly be equal.
Unnar Björnsson
Ranch Hand
Posts: 164
posted 12 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
p0 and p1 are
not
equal, what makes you think they are?
what if we put solar panels on top of the semi truck trailer? That could power this tiny 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
Need Help! How can I......
Thread - Wait() and Notify();
Generics: why doesn't this work for extending wildcards?
"=" oprator question
More...