简体   繁体   中英

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.

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.)

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"); it bombards error that create a new constructor

Edit:Class A and B are in same project

 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. None of A 's constructors will be visible to B and that is absolutely necessary.

(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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM