aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritance" Watch "Inheritance" New topic
Author

Inheritance

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: 14270
    
  21

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
Bartender

Joined: Apr 06, 2010
Posts: 4422
    
    8

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?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Inheritance