Cannot add public method to my derivation of AudioInputStream
This is probably a beginner question.
I have a class that inherits from AudioInputStream and generates various sine waves. It works fine. I want to add public methods to send it messages while running. For example I'm trying to add a setFreq(float) method that can be called after the class is instantiated. It compiles fine with this addition and the method can be called internally to the the class, but other classes cannot find this public method. I get a "cannot find symbol" error if I try to call these methods.
What is going on? Is there some sort of finalization that stops one from adding new public methods?
You can write a subclass X of AudioInputStream that has whatever public methods you like. But when you assign it to a variable whose type is AudioInputStream, the compiler (and the runtime) don't care that it's your subclass X. All they know is that it's an AudioInputStream and it has the methods of AudioInputStream, nothing else.
If you assign it to a variable of type X, then you can use all the methods of AudioInputStream and all the methods of X as well.
I mean: why isn't it a compiler error to assign a derived type to its parent type?
My code said: ParentType x = new MyDerivedType();
All I had to do was change ParentType to say MyDerivedType. I'm surprised it even compiled before this change. Java has a different idea about types than I.