Problem with protected constructor — oracle-tech

    Forum Stats

  • 3,702,038 Users
  • 2,239,552 Discussions
  • 7,835,729 Comments

Discussions

Problem with protected constructor

Tuan HaTuan Ha Posts: 1
edited August 2017 in Java Desktop Applications

I have 2 class in 2 package: class ClassOne in package1 and clas ClassTwo in package2. Class ClassTwo extends class ClassOne which have a protected constructor: protected ClassOne(String s). When i call protected constructor of ClassOne in constructor of ClassTwo it get none error but i can see it when do ctrl+space, it just show a public constructor super(). So what is this problem, why IDEs not show protected constructor when i ctrl+space?

package package1;

public class ClassOne {

    public ClassOne(){

      

    }

    protected ClassOne(String s){

        System.out.println(s);

    }

}

package package2;

import package1.ClassOne;

public class ClassTwo extends ClassOne{

    public ClassTwo(){

        super("Why this protected constructor can use but not visiable?");//i can use this constructor protected ClassOne(String s) but can see it when ctrl+space

    }

}

This discussion has been closed.