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?

[639 byte] By [dfasdfsdafsadfasdfa] at [2007-11-27 8:18:36]
# 1

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.

DrClapa at 2007-7-12 20:06:53 > top of Java-index,Java Essentials,Java Programming...
# 2
are you calling your new method on a reference of type AudioInputStream or YourAudioInputStream?
OnBringera at 2007-7-12 20:06:53 > top of Java-index,Java Essentials,Java Programming...
# 3
Problem solved. This was basically a case of an idiotic typo going undetected. I forgot to change the type declaration to the derived class.It seems bizarre to me that this is not a compiler error.
dfasdfsdafsadfasdfa at 2007-7-12 20:06:53 > top of Java-index,Java Essentials,Java Programming...
# 4
> It seems bizarre to me that this is not a compiler error.It was a compiler error according to your original post.
DrClapa at 2007-7-12 20:06:53 > top of Java-index,Java Essentials,Java Programming...
# 5

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.

dfasdfsdafsadfasdfa at 2007-7-12 20:06:53 > top of Java-index,Java Essentials,Java Programming...
# 6
> I mean: why isn't it a compiler error to assign a> derived type to its parent type?Because it's a useful technique. In fact it's fundamental to polymorphism that you can do that.
DrClapa at 2007-7-12 20:06:53 > top of Java-index,Java Essentials,Java Programming...
# 7
Finally a situation where "It's not a bug, it's a feature" can be used and not be a joke. :)
hunter9000a at 2007-7-12 20:06:53 > top of Java-index,Java Essentials,Java Programming...