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!

Diamond Problem

807600Jul 11 2007 — edited Jul 11 2007
interface A
{
	void foo();
}

abstract class B 
{
	public void foo()
	{
		System.out.println("B");
	}	
}

class C extends B implements A
{
	public void foo()
	{
		System.out.println("C");
	}
}


class Demo
{
	public static void main(String args[])
	{
		A c = new C();
		B b = new C();
		b.foo();		// prints C
		c.foo();		// prints C
	}
}
If there were 2 interfaces that were implemented in a class, i would have not complained because none has its seperate implementation defined, so which path my class followed in the inheritence hierarchy doesnt actually matter to me, since both are equivalent.

But the case i m discussing here, one of my abstract class actually has the implementation for foo(), so now I do give heed to the path followed.

Moreover, the foo() implementation in my concrete class, actually overloads both foo()'s , since inheritence and abstract class reference call to foo both print C

so does java still not experience Diamond Problem, because path followed is actually still unknown?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 8 2007
Added on Jul 11 2007
1 comment
173 views