Search code examples
javaclassconstructorprotected

Java: How to create new class object for Reader class from java.io when it has protected constructor


I wanted to create a new class object for java's Reader class, but I can't access the constructor since it is protected.

Reader Class Description

Reader myReader = new Reader(); 

Will not work.

Normally, I would create a new function that class to access that constructor, but since the function is a part of java default library, how do I access it? Thanks for any help.


Solution

  • Reader is an abstract class. You cannot instantiate it, only for the purposes of making a subclass instance.

    Did you mean

    Reader myReader = new InputStreamReader(in, "UTF-8");