Problem with protected constructor — oracle-tech

    Forum Stats

  • 3,715,723 Users
  • 2,242,844 Discussions
  • 7,845,508 Comments

Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Problem with protected constructor

Tuan Ha
Tuan Ha Member 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.