I have a doubt, following is the code for the bufferedwriter
BufferedWriter out = new BufferedWriter(new FileWriter(testcasename+".html"));
Constructor of BufferedWriter accepts only parameter of reference type ‘Writer’ abstract class, how does ‘filewriter‘ class is instantiated in the above code ?
Not sure what you mean.
But you did
new FileWriter(path) which creates aFileWriterinstance andFileWriterextendsWriterwhich makes it perfectly valid.Writerisn’t an interface but an abstract class that can be extended or subclassed etc.Interfaces are implemented. And
newcreates an object and returns a pointer or reference to that object. The reference is passed by value into theBufferedWriterconstructor (think of a constructor as a special method) which accepts aWriterobject.I really hope my explanation made it clear.