File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritance" Watch "Inheritance" New topic


archu sweet
Ranch Hand

Joined: Mar 07, 2011
Posts: 66

I want to know how come p0=p1 is true ??
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15084

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?

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
archu sweet
Ranch Hand

Joined: Mar 07, 2011
Posts: 66

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

Joined: Apr 06, 2010
Posts: 4543

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:

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

Joined: Apr 30, 2005
Posts: 164
p0 and p1 are not equal, what makes you think they are?
I agree. Here's the link:
subject: Inheritance
jQuery in Action, 3rd edition