[英]How can I call parameterized constructor of default type from a parameterized constructor of type public which is in another class?
Class B is inherited from Class A. B类是从A类继承的。
Class A have parameterized constructor of access type default which is not accessible (default:it can be accessible from different class but from same package.) A类具有参数类型的构造函数,该构造函数的访问类型为default,该类型无法访问(默认值:可以从其他类访问,但可以从同一包访问)。
How can i access my constructor of default visibility from another class? 如何从另一个类访问默认可见性的构造函数?
Here I want to access A(int id1,String s)
from public B(int id1,int h1)
,by calling super(999,"super");
在这里,我想通过调用
super(999,"super");
从public B(int id1,int h1)
访问A(int id1,String s)
super(999,"super");
it bombards error that create a new constructor 它轰炸了创建新构造函数的错误
Edit:Class A and B are in same project 编辑:A类和B类在同一项目中
public class A {
A(int id1,String s)
{
System.out.println("in parameterized constructor of class A");
}
public class B extends A{
public B(int id1,int h1)
{
super(999,"super");//The constructor A(int, String) is undefined
System.out.println("in parameterized constructor of class B");
}
If B extends A
, A
only has a default visibility constructor, and B
is not in the same package as A
, then there is absolutely 100% no way to make B
compile at all. 如果
B extends A
, A
只有一个默认的构造函数的可见性,而B
是不是在同一个包A
,则是绝对100%没有办法让B
编译的。 None of A
's constructors will be visible to B
and that is absolutely necessary. A
的构造函数都不对B
可见,这是绝对必要的。
(You can use this deliberately when you need to have a class that needs subclasses but you don't want it to be subclassable outside the package.) (当您需要一个需要子类但又不想在包外被子类化的类时,可以故意使用此方法。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.