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");

        }
1

There are 1 answers

2
Louis Wasserman On BEST ANSWER

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