Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

super.equals(this)

807601Mar 5 2008 — edited Mar 5 2008
After thinking for a while about the keywords 'this' and 'super' I concluded that they both refer to the same location in memory. To test this out I wrote the folowing code:
public class Test {
	public static void main(String[] args){
		B b = new B();
		System.out.print(b.test());
	}
}

class A{
	public A(){
	}
}

class B extends A{
	public B(){
	}

	public boolean test(){
		return (super.equals(this));
	}
}
After running this program, the consoleOutput reads: 'true', so my idea seems to be right. Can someone agree with this?
A second question is why the same doesn't work when I change "super.equals(this)" by "this.equals(super)" or by "super==this" or by "this==super". Shouldn't 'equals' be symmetrical?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 2 2008
Added on Mar 5 2008
10 comments
1,120 views