Accessing specific class if condition is true
I'm making a trigonometry application with the different formulas for each shapes and such. What I wanted to know is: is there any way to make a boolean and access a specific class if this boolean is true?
Since I'm making Degree and Radian sub-classes, I needed to make it so when the boolean isInDegrees is true, it accesses Degree class, and the inverse if isInRadian is true.
Re: Accessing specific class if condition is true
Re: Accessing specific class if condition is true
why not write a method to do this work?
not sure if you are being told how to do something, but inheritance will handle most of your situations for you
write the methods you need in every subclass, as well as a place holder method in the superclass (i think its something like public <returntype> <name>; that will force the subclasses to have the method "public <returntype> <name>(){//stuff}
you make an instance of the superclass object (parent to both Degree and Radian) then call your methods, and it will automatically use the right one through the power of polymorphism. (hence no need for the booleans)