Skip to Main Content

Java Programming

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!

protected constructor not visible in a sub class

807589Nov 19 2008 — edited Nov 20 2008
hi all
i have two classes:
package base;

public class Super
{
	protected Super()
	{
	}
}
and
package base.inner;

import base.Super;

public class Sub extends Super
{
	public Sub()
	{
		super();
	}
	
	public void func()
	{
		new Super();
	}
}
Eclipse says that i can call "new Super()" because it is not visible. It suggests to change the Super constructor to be protected (which is already!). Note that the two classes are in different packages. If they are in the same one, it compiles ok.

anyone know y? can protected constructors only be called as "super()" in the sub classes and not to create real super objects in the sub classes?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 18 2008
Added on Nov 19 2008
11 comments
622 views